链表
月半明时
过去心不可得 现在心不可得 未来心不可得
展开
-
【Leetcode】83. Remove Duplicates from Sorted List - 从顺序链表中删除冗余元素
设置一个fast,一个slow如果fast的值与slow不同,则slow链接到fast相同则slow原地不动看了一眼其他人写的,好像还要释放空间???【存疑】原创 2016-08-03 13:52:52 · 332 阅读 · 0 评论 -
【Leetcode】141. Linked List Cycle-判断链表是否有环
快慢指针原创 2016-08-02 08:54:39 · 559 阅读 · 0 评论 -
Linked List - 单链表找中点 - 快慢指针
快慢指针原创 2016-08-01 17:10:04 · 1406 阅读 · 0 评论 -
【Leetcode】234. Palindrome Linked List -判断链表是否为回文序列
快慢指针法找到链表中点 http://blog.csdn.net/vlin_hao/article/details/52087367将后半段链表反转 *head*pre*cur两个指针逐个比较原创 2016-08-02 09:09:26 · 313 阅读 · 0 评论 -
【Leetcode】19. Remove Nth Node From End of List - 删掉链表倒数第n个节点
快慢指针初始fast比slow快n步 当fast->next == NULL 删掉slow->next重要的是边界,边界,边界!原创 2016-08-02 13:54:12 · 262 阅读 · 0 评论 -
【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 · 415 阅读 · 0 评论 -
【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 · 443 阅读 · 0 评论 -
【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 · 274 阅读 · 0 评论 -
【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 · 287 阅读 · 0 评论