摘要: LeetCode 21 Merge Two Sorted Lists/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */stru... 阅读全文
posted @ 2015-11-23 10:25 Walker_Lee 阅读(100) 评论(0) 推荐(0) 编辑
摘要: LeetCode 232 Implement Queue using Stacksclass Queue { stack input, output;public: void push(int x) { input.push(x); } void pop(voi... 阅读全文
posted @ 2015-11-23 09:22 Walker_Lee 阅读(102) 评论(0) 推荐(0) 编辑
摘要: LeetCode 202 Happy Number主要用到了 如果循环里存在4则unhappybool isHappy(int n) { if(n==1) return true; if(n==4) return false; int sum=0; ... 阅读全文
posted @ 2015-11-19 09:31 Walker_Lee 阅读(129) 评论(0) 推荐(0) 编辑
摘要: LeetCode 263 Ugly Number很多人出现Time Limit Exceeded的情况,是由于没有判断num是否等于0.bool isUgly(int num) { if(num==0) return false; while(num%2 == 0) ... 阅读全文
posted @ 2015-11-18 16:43 Walker_Lee 阅读(132) 评论(0) 推荐(0) 编辑
摘要: LeetCode 83 Remove Duplicates from Sorted List/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next;... 阅读全文
posted @ 2015-11-17 10:24 Walker_Lee 阅读(108) 评论(0) 推荐(0) 编辑
摘要: LeetCode 70 Climbing Stairs使用递归方法,超时int climbStairs(int n) { if(n=2)int climbStairs(int n) { if (n == 0 || n == 1) return 1; int pre = 1... 阅读全文
posted @ 2015-11-17 09:53 Walker_Lee 阅读(111) 评论(0) 推荐(0) 编辑
摘要: LeetCode 206 Reverse Linked List递归:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */str... 阅读全文
posted @ 2015-11-17 09:22 Walker_Lee 阅读(117) 评论(0) 推荐(0) 编辑
摘要: LeetCode 169 Majority Element可以先排序,再return中位数,但估计这种方法不会被面试官认可。这里用到了Moore’s voting algorithm http://www.cs.utexas.edu/~moore/best-ideas/mjrty/example.h... 阅读全文
posted @ 2015-11-16 09:44 Walker_Lee 阅读(108) 评论(0) 推荐(0) 编辑
摘要: LeetCode 191 Number of 1 Bitshttps://en.wikipedia.org/wiki/Hamming_weightint hammingWeight(uint32_t n) { int num=0; while(n!=0) { n&=(... 阅读全文
posted @ 2015-11-16 09:16 Walker_Lee 阅读(83) 评论(0) 推荐(0) 编辑
摘要: LeetCode 235 Lowest Common Ancestor of a Binary Search Tree/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct Tr... 阅读全文
posted @ 2015-11-16 09:07 Walker_Lee 阅读(147) 评论(0) 推荐(0) 编辑