摘要:        
对这种树的操作,已经比较熟练了。class Solution {public: int sumNumbers(TreeNode *root) { int sum = 0; calculate(root, 0, sum); return sum; } void calculate(TreeNode *root, int currentSum, int& sum) { if (root == NULL) return; currentSum = currentSum * 10 + root->va...    阅读全文
posted @ 2013-09-11 23:44
阿牧遥
阅读(137)
评论(0)
推荐(0)
        
            
        
        
摘要:        
这道题目一看就去翻答案了,因为以前见过,知道并查集可以用来做分组,但这样的题目真的要并查集么?想想也是HashSet之类就能搞定么。果然是HashMap而不是HashSet。下面这个解法我比较容易理解,刚开始乍看发现对每一个n又要左边遍历右边遍历的,仔细一看对每一段遍历过的数字就标记一下,那么保证每个数字只访问一次,还是O(n)。public class Solution { public int longestConsecutive(int[] num) { HashMap map = new HashMap(); int max = 0; f...    阅读全文
posted @ 2013-09-11 23:13
阿牧遥
阅读(257)
评论(0)
推荐(0)
        
            
        
        
摘要:        
有一道链表的题目。今天面试别人出了链表的题目都被答出来了,可见这个一般训练过还是能做出来的,就是考虑corner case即可。这里主要是m为1的时候,head就要变了。class Solution {public: ListNode *reverseBetween(ListNode *head, int m, int n) { ListNode* current = head; ListNode* last = NULL; int i = 1; while (i != m && current != NULL) { ...    阅读全文
posted @ 2013-09-11 22:37
阿牧遥
阅读(167)
评论(0)
推荐(0)
        
 
                    
                     
                    
                 
                    
                
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号