The Travels of Marco Cai

  • Home

  • About

  • Tags

  • Archives

  • Search

[LeetCode] Challenge log 21

Posted on 2018-07-11 | Edited on 2018-07-12 |
21. Merge Two Sorted Lists

Basic linklist operation.

Read more »

[LeetCode] Challenge log 143

Posted on 2018-07-11 | Edited on 2018-07-12 |
143. Reorder List

Algorithm:

  1. split the linklist
  2. reverse the second half
  3. merge one by one
Read more »

[LeetCode] Challenge log 61

Posted on 2018-07-11 | Edited on 2018-07-12 |
61. Rotate List

Analysis:

  1. It is equivalent to finding the last k nodes and make them the head.
  2. If k > len(list), k = k % len(list)

Algorithm:

  1. let fast be k steps ahead of slow.
  2. forward both pointer until fast is the last node
  3. now slow is the pre of the last kth node
Read more »

[LeetCode] Challenge log 92

Posted on 2018-07-11 | Edited on 2018-07-12 |
92. Reverse Linked List II

Algorithm:

  1. find (m-1)th node
  2. reverse (n-m+1) nodes
Read more »

[LeetCode] Challenge log 206

Posted on 2018-07-11 | Edited on 2018-07-12 |
206. Reverse Linked List

Basic linklist operation. It can be done either recursively or iteritively.

Read more »

[LeetCode] Challenge log 83

Posted on 2018-07-11 | Edited on 2018-07-12 |
83. Remove Duplicates from Sorted List

Algorithms: while traverse the link, delete cur if cur == cur.next.

Read more »

[LeetCode] Challenge log 19

Posted on 2018-07-11 | Edited on 2018-07-12 |
19. Remove Nth Node From End of List

The trick is to create two pointers. One is n steps faster.

Read more »

[LeetCode] Challenge log 7

Posted on 2018-07-05 |
7. Reverse Integer

Normal question, but be aware of the upper bound and lower bound.

Read more »

[LeetCode] Challenge log 2

Posted on 2018-07-05 |
2. Add Two Numbers
  1. Use recursion to process node by node.
  2. When there is carry, create a new node with val = 1 to add on.
Read more »

[LeetCode] Challenge log 167

Posted on 2018-06-25 |
167. Two Sum II - Input array is sorted

Same as #1, #653. Either use set or two pointers.

Read more »
1234…13
Mingxiang Cai

Mingxiang Cai

A learner, a hobbyist.

128 posts
56 tags
© 2019 Mingxiang Cai
0%