![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
linked list
feeeeeeet
这个作者很懒,什么都没留下…
展开
-
Leetcode 19. Remove Nth Node From End of List
Faster pointer go first, after n steps there are len-n numbers. Then two pointers go together until there is no number faster pointer points to(len-n steps). Slower pointer points to the n-th node fro...原创 2018-11-14 09:09:36 · 63 阅读 · 0 评论 -
Leetcode 25. Reverse Nodes in k-Group
extend from Leetcode 24 0(q)-1(head)-2-3-4-5-6 0(q)-2-1(head)-3-4-5-6 0-3-2-1(q)-4(head)-5-6 class Solution { public ListNode reverseKGroup(ListNode head, int k) { ListNode res=new ListNode(0); ...原创 2018-11-19 06:19:57 · 60 阅读 · 0 评论 -
Leetcode 21. Merge Two Sorted Lists
Complicated Version Part 1 should be the first part, otherwise the program couldn’t pass the following case. In the last iteration, we have flag=0 and l2==null, so the program can’t run part 2. input...原创 2018-11-15 03:44:32 · 67 阅读 · 0 评论 -
Leetcode 24. Swap Nodes in Pairs
2 solutions - use two extra pointers & recursive Solution 1 use two extra pointers class Solution { public ListNode swapPairs(ListNode head) { ListNode res=new ListNode(-1); re...原创 2018-11-15 06:17:42 · 180 阅读 · 0 评论 -
Leetcode 82&83. Remove Duplicates from Sorted List I & II
recursion can be used in II difference between pre=cur(the same node) and pre.val=cur.val (two nodes have the same number) Remove Duplicates from Sorted List I 2 solutions slow version # Definition fo...原创 2018-12-31 00:24:20 · 112 阅读 · 0 评论 -
Leetcode 86. Partition List
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def partition(self, head, x): """ ...原创 2018-12-31 07:08:29 · 93 阅读 · 0 评论 -
Leetcode 61. Rotate List
Calculate the length of the list and use k%length. # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution...原创 2018-12-26 00:29:28 · 87 阅读 · 0 评论