- 博客(13)
- 收藏
- 关注
原创 【leetcode】387. First Unique Character in a String 首个单字符
int firstUniqChar(char* s) { int len=strlen(s); int abc[26]={0}; int i=0; while (i<len){ abc[s[i]-'a']++; i++; } i=0; while (i<len){ if (abc[s[i]-'a'
2016-09-20 15:28:27
321
原创 【leetcode】383. Ransom Note 恐吓信
bool canConstruct(char* ransomNote, char* magazine) { int len1=strlen(ransomNote); int len2=strlen(magazine); int abc[26]={0}; if (len1>len2){ return false; } int i=0;
2016-09-20 15:22:49
421
原创 【Leetcode】61. Rotate List - 循环链表
思路: 1. 遍历链表找到结尾,顺便统计链表长度count 2. 将结尾指向head,使链表首位相连,并计算前行长度count=count-k%count 3. 前行count步,当前指针为尾,next为new head/** * Definition for singly-linked list. * struct ListNode { * int val; * st
2016-08-11 14:55:47
336
原创 【Leetcode】143. Reorder List - 链表重排序
思路: 1. 快慢指针法找到中点 2. 后半段链表逆序 3. 两个指针穿针引线注意点: 传统快慢指针法找到的中点是后半段的起点,应该让slow慢一拍,以方便设置前半段的结尾为NULL/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *nex
2016-08-11 13:37:22
313
原创 【Leetcode】203. Remove Linked List Elements - 移除链表内特定的元素
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* removeElements(struct ListNode* head, int val) { if (head==NU
2016-08-09 13:49:49
473
原创 【leetcode】24. Swap Nodes in Pairs - 成对交换链表元素
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* swapPairs(struct ListNode* head) { if (head==NULL||head->next
2016-08-06 13:37:53
441
原创 【Leetcode】83. Remove Duplicates from Sorted List - 从顺序链表中删除冗余元素
设置一个fast,一个slow如果fast的值与slow不同,则slow链接到fast相同则slow原地不动看了一眼其他人写的,好像还要释放空间???【存疑】
2016-08-03 13:52:52
383
原创 【Leetcode】19. Remove Nth Node From End of List - 删掉链表倒数第n个节点
快慢指针初始fast比slow快n步 当fast->next == NULL 删掉slow->next重要的是边界,边界,边界!
2016-08-02 13:54:12
299
原创 【Leetcode】234. Palindrome Linked List -判断链表是否为回文序列
快慢指针法找到链表中点 http://blog.youkuaiyun.com/vlin_hao/article/details/52087367将后半段链表反转 *head*pre*cur两个指针逐个比较
2016-08-02 09:09:26
343
原创 欢迎使用优快云-markdown编辑器
欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl
2016-08-01 16:21:12
303
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人