![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode之linked list
文章平均质量分 74
Shawn_Redemption
这个作者很懒,什么都没留下…
展开
-
【Leetcode】Rotate List (lastN)
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.这道题rang原创 2014-10-25 23:02:45 · 361 阅读 · 0 评论 -
【Leetcode】Insertion Sort List (Sorting)
这道题让采用插入排序的方式排链表基本思路是构造一个单独的helper,原创 2014-10-29 07:43:26 · 314 阅读 · 0 评论 -
【Leetcode】Linked List Cycle II (Walker_Runner)
这道题和1差不多,只是让寻找开始节点定义walker和runner并且同时指向head。walker一次走一步,runner一次走两步,runner为空或走到末尾则跳出循环。如果walker和runner相遇,则存在cycle。此时跳出循环,否则返回空。然后让walker回到head,walker和runner同时走一步,直到相遇,那个节点就是cycle的开始节点。代码原创 2014-10-25 03:26:11 · 402 阅读 · 0 评论 -
【Leetcode】Merge K Sorted Lists (Sorting)
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.这道题原创 2014-10-29 08:36:41 · 408 阅读 · 0 评论 -
【Leetcode】Partition List (Swap)
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of原创 2014-10-28 09:13:07 · 554 阅读 · 1 评论 -
【Leetcode】Swap Nodes in Pairs (Swap)
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2014-10-27 03:01:45 · 376 阅读 · 0 评论 -
【Leetcode】Reverse Linked List II (Swap)
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the原创 2014-10-27 03:21:15 · 277 阅读 · 0 评论 -
【Leetcode】Reverse Nodes in k-Group (Swap)
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is原创 2014-10-27 10:15:13 · 339 阅读 · 0 评论 -
【Leetcode】Linked List Cycle (Walker_Runner)
这道题让判断链表中是否存在cycle思路采用walker_runner法原创 2014-10-25 03:23:39 · 311 阅读 · 0 评论 -
【Leetcode】Add Two Numbers (2 lists)
这道题是将两个链表相加Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)Output: 7 -> 0 -> 8主要是进位的处理,如果进位原创 2014-10-25 10:12:25 · 329 阅读 · 0 评论 -
【Leetcode】Merge Two Sorted Lists (2 lists)
题目要求合并两个排好序的链表,这道题和add 2 number 思路比较类似,都是gou'zao原创 2014-10-25 09:01:39 · 386 阅读 · 0 评论 -
【Leetcode】Remove Nth Node From End of the List (lastN)
此题让删除链表中的倒数第K个元素,思路如下原创 2014-10-25 08:37:33 · 341 阅读 · 0 评论 -
【Leetcode】Remove Duplicates from Sorted List (Removing)
题目让从一个排好序的链表中删除重复的元素,使得重复的元素只出现一次。s原创 2014-10-25 23:59:44 · 317 阅读 · 0 评论 -
【Leetcode】Remove Duplicates from Sorted List II (Removing)
题目让从一个排好序的链表中删除重复的元素,使得重复的元素一次也不出现。思路是采取差一法。差一法:即要删除一个链表节点的时候,往往需要保持这个节点的前置节点,所以在判断要删除节点的时候直接采取node.next.val与目标值进行比较,而不是用node.val和目标值进行比较,也就是用下一个节点的值和目标值比较。这种方法叫做差一法。原创 2014-10-26 00:34:10 · 409 阅读 · 0 评论 -
【Leetcode】Reorder List (Walker_Runner)
这道题让把一串链表1,2,3...n-1,n变成1,n-1, 2, n-2基本思想是把整个链表chong切割成原创 2014-10-25 04:29:19 · 468 阅读 · 1 评论 -
【Leetcode】Sort List (Sorting)
此题要求用归并排序排两个链表,基本思想还是分为分割和合并合并的代码在Merge Two Sorted List里已经讲得很清楚了。所以这里直接给出代码。原创 2014-10-29 08:16:32 · 567 阅读 · 0 评论