摘要:
示例思路一:两个链表同时逐个遍历参考代码ListNode* combinList(ListNode *head_1, ListNode *head_2){ ListNode *head_3 = NULL; if(head_1 == NULL) { head_3 = head_2; } else if(head_2 == NULL) { head_3 = head_2; } else { ListNode *p1 = head_1; ListNode *p2 = head_2; ... 阅读全文
posted @ 2014-03-18 23:21
jihite
阅读(706)
评论(2)
推荐(1)
摘要:
策略直接遍历总数为len,再次遍历第len-k+1个就是答案,但是这样遍历了O(N+k)个,可以在O在更短的时间内找到图示参考代码#include using namespace std;typedef struct ListNode{ int value; ListNode* next;}ListNode;void createList(ListNode *&head){ head = new(ListNode); head->value = 1; head->next = NULL; ListNode *p2 = new(ListNode); p2... 阅读全文
posted @ 2014-03-18 16:48
jihite
阅读(2470)
评论(0)
推荐(0)
摘要:
案例数组内容:3 4 4 6 8 2 1 1 1调换奇偶:3 1 1 1 8 2 4 4 6思路源于快速排序方式1参考代码#include #include using namespace std;bool IsOdd(int num){ return num % 2 == 1 ? true ... 阅读全文
posted @ 2014-03-18 10:51
jihite
阅读(4472)
评论(2)
推荐(0)
摘要:
比如n = 2那么从1一直输出到99分析直接输出,遇到大数时肯定有问题,比如n=100,存储100位的数据类型不存在。可以利用数组来存储大数,比如n=100,可以开辟个数组 char a[101]思路一模拟现实中的技术方式,逢九进一参考代码#include #include using namespace std;bool minuxOne(char *a, int *end_index, int size){ if((*end_index == size - 1 && a[size - 1] == '0') || *end_index = size) retu 阅读全文
posted @ 2014-03-18 10:08
jihite
阅读(2870)
评论(0)
推荐(0)

浙公网安备 33010602011771号