上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 25 下一页
摘要: int minthree(int a1, int a2, int a3){ a1 = a1 q2, q3, q5; int res = 1; q2.push(2); q3.push(3); q5.push(5); while(index > 1){ --index; int tp = minthree(q2.front(), q3.front(), q5.front()); if(tp == q2.front()){ q2.pop(); q2.push(tp*2); q3.push(tp*3); q5.push(tp*5); }else if(tp == q3.fro... 阅读全文
posted @ 2013-09-16 16:22 冰点猎手 阅读(210) 评论(0) 推荐(0)
摘要: const int g_maxlen = 10;char * g_strCombine1 = new char[g_maxlen*2 +1];char * g_strCombine2 = new char[g_maxlen*2 +1];int compare(const void *str1, const void *str2){ strcpy(g_strCombine1, *(const char **)str1); strcat(g_strCombine1, *(const char **)str2);// important strcpy(g_strCombine2, *(const c 阅读全文
posted @ 2013-09-16 15:26 冰点猎手 阅读(185) 评论(0) 推荐(0)
摘要: >的解释没有编程之美的解释好。建议这题看编程之美的解释long long CountOne(long long n){ long long iCount = 0; long long ifactor = 1; long long ilower, icur, ihigher; while( n/ifactor != 0) { ilower = n % ifactor ; icur = (n/ifactor )%10 ; ihigher = n/(ifactor*10); switch(icur){ case 0: iCount += ihigher * ifactor;... 阅读全文
posted @ 2013-09-16 14:52 冰点猎手 阅读(217) 评论(0) 推荐(0)
摘要: 编程之美中的思路。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)
摘要: 题目: 给定一个整数数组, 判断该数组是不是某二叉搜索的后续遍历序列。假设输入的数组的任意两个数字都互不相同。分析: 对于某种访问序列的verify的问题,一般先找到根节点,然后根据题目信息找出左子树与右子树。然后根据当前信息判断当前根节点的合法性,然后递归判断左子树和右子树的合法性。bool varify(int A[], int length){ if(A == NULL || lenght root) break; } for(j = i; j 0) left = verify(A, i); if(i != len -1) right = verify(A + i... 阅读全文
posted @ 2013-09-14 23:25 冰点猎手 阅读(181) 评论(0) 推荐(0)
摘要: Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solution is trivial, could you do it iteratively? /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode ... 阅读全文
posted @ 2013-09-14 23:01 冰点猎手 阅读(156) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 25 下一页