上一页 1 2 3 4 5 6 ··· 20 下一页
摘要: 思路理清楚就好。 ListNode *partition(ListNode *head, int x) { // Note: The Solution object is instantiated only once and is reused by each test case. if(head==NULL) return NULL; ListNode* smallHead,*smallTail,*bigHead,*bigTail,*cur,*next; smallHead = smallTail = big... 阅读全文
posted @ 2013-10-25 14:54 summer_zhou 阅读(130) 评论(0) 推荐(0) 编辑
摘要: int singleNumber(int A[], int n) { // Note: The Solution object is instantiated only once and is reused by each test case. if(n cnt(32,0); int res = 0; for(int i=0;i>i)&1==1) cnt[i] = (cnt[i]+1)%3; } ... 阅读全文
posted @ 2013-10-25 13:47 summer_zhou 阅读(139) 评论(0) 推荐(0) 编辑
摘要: //recursive ListNode *deleteDuplicates(ListNode *head) { // Note: The Solution object is instantiated only once and is reused by each test case. if(!head||!head->next) return head; ListNode* p = head->next; if(head->val == p->val) { while(head... 阅读全文
posted @ 2013-10-25 11:08 summer_zhou 阅读(141) 评论(0) 推荐(0) 编辑
摘要: BFS UndirectedGraphNode *cloneGraph(UndirectedGraphNode *node) { // Note: The Solution object is instantiated only once and is reused by each test case. if(node==NULL) return NULL; map nmap; UndirectedGraphNode* copynode = new UndirectedGraphNode(node->label... 阅读全文
posted @ 2013-10-24 22:42 summer_zhou 阅读(108) 评论(0) 推荐(0) 编辑
摘要: int minCut(string s) { // Note: The Solution object is instantiated only once and is reused by each test case. if(s.empty()) return 0; int n = s.size(); vector> bPalin(n,vector(n,false)); int i,j; for(i=0;i=0;i--) for(j=i+2;j dp(n)... 阅读全文
posted @ 2013-10-24 16:41 summer_zhou 阅读(126) 评论(0) 推荐(0) 编辑
摘要: BFS int ladderLength(string start, string end, unordered_set &dict) { // Note: The Solution object is instantiated only once and is reused by each test case. int len = 1; unordered_set strs; queue q; q.push(start); strs.insert(start); ... 阅读全文
posted @ 2013-10-23 22:57 summer_zhou 阅读(173) 评论(0) 推荐(0) 编辑
摘要: vector letterCombinations(string digits) { // Note: The Solution object is instantiated only once and is reused by each test case. string maps[] = {"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; vector res; dfs(0,di 阅读全文
posted @ 2013-10-23 20:02 summer_zhou 阅读(148) 评论(0) 推荐(0) 编辑
摘要: void setZeroes(vector > &matrix) { // Note: The Solution object is instantiated only once and is reused by each test case. if(matrix.empty()) return; int m = matrix.size(); int n = matrix[0].size(); bool first_row,first_col; first_row = first_... 阅读全文
posted @ 2013-10-23 19:18 summer_zhou 阅读(102) 评论(0) 推荐(0) 编辑
摘要: 递归 void flatten(TreeNode *root) { // Note: The Solution object is instantiated only once and is reused by each test case. flat(root); } TreeNode* flat(TreeNode* root) { if(!root) return NULL; TreeNode* left_tail = flat(root->left); TreeNo... 阅读全文
posted @ 2013-10-23 18:56 summer_zhou 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 问题的本质就是:树的level-order遍历 TreeLinkNode* getNextSibling(TreeLinkNode* cur) { while(cur) { if(cur->left) return cur->left; if(cur->right) return cur->right; cur = cur->next; } return NULL; }class Solution {public: void connect(TreeLinkNode... 阅读全文
posted @ 2013-10-23 15:10 summer_zhou 阅读(162) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 20 下一页