Linked List

Linked List: Link to heading

707

反转 Link to heading

public ListNode reverseList(ListNode cur) {
  ListNode prev = null;
  while (cur != null) {
      // step1: save cur.next node & set cur.next as prev
      ListNode after = cur.next;
      cur.next = prev;
      // step2: update prev as cur & update cur to saved node
      prev = cur;
      cur = after;
  }
  return prev;
}
public ListNode reverseList(ListNode head) {
    if (head == null || head.next == null) {
        return head;
    }
    ListNode p = reverseList(head.next);
    head.next.next = head;
    head.next = null;
    return p;
}

操作一个链表 Link to heading

借助其他 data structure 存储信息 Link to heading

Question
138

反转系列 Link to heading

Question
24, 92, 206, 234

Sliding Window Link to heading

Question
19, 61,

双指针 Link to heading

Question
19, 82, 86, 141, 142, 147, 287, 328, 708, 2807

操作两个链表 Link to heading

Question
2, 21, 23, 160

Merge Link to heading

Question
143, 148,