随笔分类 -  LeetCode

摘要:class Solution { public: int lengthOfLongestSubstring(string s) { int hashTable[255]; fill(hashTable, hashTable+255, -1); int start = 0, maxLen = 0; for(i... 阅读全文
posted @ 2017-06-17 17:51 chengcy 阅读(106) 评论(0) 推荐(0)
摘要:方法:记录便利过程中的best profit Best Time to Buy and Sell Stock II 阅读全文
posted @ 2017-06-17 15:56 chengcy 阅读(179) 评论(0) 推荐(0)
摘要:方法:使用一个变量记录能到达的最远距离 Jump Game II 阅读全文
posted @ 2017-06-10 20:00 chengcy 阅读(156) 评论(0) 推荐(0)
摘要:方法:采用二分查找 阅读全文
posted @ 2017-06-10 19:02 chengcy 阅读(136) 评论(0) 推荐(0)
摘要:方法:采用分治的方法,x^n = x^n/2*x^n/2*x^n%2; 阅读全文
posted @ 2017-06-10 18:12 chengcy 阅读(104) 评论(0) 推荐(0)
摘要:方法:使用递归的方式实现: 阅读全文
posted @ 2017-06-10 18:02 chengcy 阅读(151) 评论(0) 推荐(0)
摘要:方法:采用递归的方式 Valid Sudoku 判别方法同上 阅读全文
posted @ 2017-06-10 17:07 chengcy 阅读(188) 评论(0) 推荐(0)
摘要:方法:采用递归的方式 Combination Sum II 方法:每次递归中当前数据只访问一次,这里面需要注意一个细节问题:当原始vector中存在重复数字时,最终的结果会出现重复 也可以使用一个简单的flag变量 Combination Sum III 方法同上 阅读全文
posted @ 2017-06-03 15:33 chengcy 阅读(138) 评论(0) 推荐(0)
摘要:方法:采用递归的方式 阅读全文
posted @ 2017-06-03 14:34 chengcy 阅读(142) 评论(0) 推荐(0)
摘要:方法一:动态规划 方法二:备忘录法 阅读全文
posted @ 2017-05-20 17:49 chengcy 阅读(120) 评论(0) 推荐(0)
摘要:方法一:直接使用备忘录 方法二:使用动态规划的方法 阅读全文
posted @ 2017-05-20 16:40 chengcy 阅读(117) 评论(0) 推荐(0)
摘要:方法:使用深度遍历的方法,时间复杂度O(2^n) 阅读全文
posted @ 2017-05-20 15:52 chengcy 阅读(124) 评论(0) 推荐(0)
摘要:方法:使用递归的思想 这个问题与上一个问题的不同之处在于其在每个数字对应的字母中只能选择一个,这里的关键是对递归的过程有比较好的认识。 阅读全文
posted @ 2017-05-11 21:04 chengcy 阅读(118) 评论(0) 推荐(0)
摘要:方法一:使用深度遍历的方式,时间复杂度O(n!) 阅读全文
posted @ 2017-05-11 20:36 chengcy 阅读(152) 评论(0) 推荐(0)
摘要:方法:采用递归的方式 或者使用查找的方式代替visit参数 对于Permutations II,只需判断现在访问到的数字与前一个是否相同即可。 阅读全文
posted @ 2017-05-07 15:30 chengcy 阅读(149) 评论(0) 推荐(0)
摘要:方法:最简单的是使用subset的方法,然后去除重复即可,这里需要对原始的vector先进行排序 阅读全文
posted @ 2017-05-07 14:54 chengcy 阅读(119) 评论(0) 推荐(0)
摘要:方法:使用一个vector记录数字是否被选中,惨痛的教训,不要把==写成=。。。。 阅读全文
posted @ 2017-05-07 14:35 chengcy 阅读(128) 评论(0) 推荐(0)
摘要:方法:采用二分查找的方法,注意rt = rows*cols-1; 阅读全文
posted @ 2017-05-07 10:33 chengcy 阅读(117) 评论(0) 推荐(0)
摘要:方法:使用逼近的方法,先寻找左边边界,再找右边界,这与二分查找中边界的更新顺序相关 或者直接找到一个值后左右逼近即可。 阅读全文
posted @ 2017-05-06 12:33 chengcy 阅读(121) 评论(0) 推荐(0)
摘要:方法:别弄反数字之间的位置关系就可以了 阅读全文
posted @ 2017-04-30 10:50 chengcy 阅读(126) 评论(0) 推荐(0)