2016年8月18日

摘要: 这个题和组合很像,但是排列需要把所有的可能都列出来,所以不需要记住位置,每一层都是从0开始循环。相应的,它需要一个数组,在每一层的时候把是否加过这个数字记下来,最后remove的时候需要把这个flag归位。 (这个题还有非recursive的做法,需要再看) 阅读全文
posted @ 2016-08-18 08:01 codingEskimo 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 这个题和permutation以及subset一样, 也属于排列组合问题, 用recursive做。 这种题的时间消耗都是指数级别的 注意for loop里面的第二个if语句是要除去重复的数列,例如{2,2,3,6,7} target 7, 第二个2不需要再次考虑,因为作用和第一个相同,需要注意的是 阅读全文
posted @ 2016-08-18 07:56 codingEskimo 阅读(117) 评论(0) 推荐(0) 编辑

2016年8月8日

摘要: Given a list of numbers that may has duplicate numbers, return all possible subsets class Solution { /** * @param S: A set of numbers. * @return: A li 阅读全文
posted @ 2016-08-08 09:19 codingEskimo 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Given a set of distinct integers, return all possible subsets. 这是一道排列与组合的问题, 对于这种题目就是求所有的方案,其中90%是用搜索, 而搜素的题目90%会用到递归。 这类题目的模版 1)把现在结果加进去 2)用for loop做 阅读全文
posted @ 2016-08-08 08:27 codingEskimo 阅读(169) 评论(0) 推荐(0) 编辑

2016年8月3日

摘要: Given two sorted integer arrays A and B, merge B into A as one sorted array. Notice You may assume that A has enough space (size that is greater or eq 阅读全文
posted @ 2016-08-03 11:16 codingEskimo 阅读(169) 评论(0) 推荐(0) 编辑

2016年7月19日

摘要: Using O(1) time to check whether an integer n is a power of 2. Example For n=4, return true; For n=5, return false; 思路: 知识点: n & (n - 1) 使得从右边数最后一个1变为 阅读全文
posted @ 2016-07-19 11:43 codingEskimo 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 参考http://www.hawstein.com/posts/5.1.html 方案1:先将N中第0位到第i位保存下来(左闭右开:[0, i)),记作ret, 然后将N中第0位到第j位全清0([0, j]),通过向右移动j+1位然后再向左移动j+1位得到。 最后用上面清0后的值或上(m«i)再或上 阅读全文
posted @ 2016-07-19 11:40 codingEskimo 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 方法一: 数学方法,先找到最大的值,需要比较最大的值和array size, 要是比array size小, 说明最大值missing。 然后用等差数列公式求得如果不缺失值的和,然后再减去array里数的和。 方法二: 先把不缺失的所有数取xor, 然后再对数组里的数取xor, 剩下的就是最后的结果 阅读全文
posted @ 2016-07-19 11:37 codingEskimo 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 方法二: num & (num -1) 一直就把最后一个非0位变成1, 一直变到所有的都是0, 那么process了几次, 就是有几位1 阅读全文
posted @ 2016-07-19 11:11 codingEskimo 阅读(101) 评论(0) 推荐(0) 编辑

2016年7月5日

摘要: Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your al 阅读全文
posted @ 2016-07-05 10:59 codingEskimo 阅读(171) 评论(0) 推荐(0) 编辑

导航