摘要: 编程之美中的思路。int MoreThanHalf(int A[], int length){ if(A == NULL || length < 1) return 0; int result = A[0]; int times = 1; for(int i = 1; i < length; ++i) { if(times == 0){ result = A[i]; times = 1; }else if(A[i] == result){ ++times; }else --times; } return result; } 阅读全文
posted @ 2013-09-15 20:34 冰点猎手 阅读(201) 评论(0) 推荐(0)
摘要: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combination.Note:All numbers (including target) will be positive integers.Elements in a combination (a1, a2, � , 阅读全文
posted @ 2013-09-15 19:25 冰点猎手 阅读(155) 评论(0) 推荐(0)
摘要: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number of times.Note:All numbers (including target) will be positive integers.Elements in a combination (a1, a 阅读全文
posted @ 2013-09-15 17:58 冰点猎手 阅读(179) 评论(0) 推荐(0)
摘要: 中序遍历的应用。struct Node{ int val; Node *left; Node *right; Node(int a): val(a), left(NULL), right(NULL){}};Node * Convert(Node *root){ if(root == NULL) return NULL; Node *head, *pNode, *p; head = pNode = NULL; stack mys; p = root; while(!mys.empty() || p != NULL){ while(p != NULL){ mys.push(p); p =... 阅读全文
posted @ 2013-09-15 15:27 冰点猎手 阅读(195) 评论(0) 推荐(0)
摘要: struct ListNode{ int val; ListNode *next; ListNode *sibling; ListNode(int a):val(a),next(NULL),sibling(NULL){}};void CloneNode(ListNode * head){ ListNode *pNode = head; while(pNode != NULL){ LiseNode *p = new ListNode(pNode->val); p->next = pNode->next; pNode->next = p; pNode = p->nex 阅读全文
posted @ 2013-09-15 15:08 冰点猎手 阅读(205) 评论(0) 推荐(0)