Dummy Node
When?
206 Reverse list
// iterative
public ListNode reverseList(ListNode head) {
if (head == null) return head;
ListNode dummy = new ListNode(0);
dummy.next = head;
while(head.next != null){
ListNode tmp = head.next;
head.next = tmp.next;
tmp.next = dummy.next;
dummy.next = tmp;
}
return dummy.next;
}
// recursive
public ListNode reverseList(ListNode head){
if(head == null || head.next == null) return head;
ListNode p = reverseList(head.next);
// head.next 是 p 裡面的最後一個, 將 head 移到最後
head.next.next = head;
head.next = null;
return p;
}92 Reverse sublist

25 Reverse Nodes in k-Groups
143 Reorder List
82 Remove all duplicates
86 Partition
Sort List
328. Odd Even Linked List
Last updated