Search
  • Zhiguo Lai

LeetCode 143

1.LinkedList

The problem can be divided by three steps:

  1. Find the middle elements with two pointers

  2. Reverse the right part by using 3 pointers, we can use the fast pointer before to save more space.

  3. Merge two linked list, check whether the right part have the next node.

2.Array

The problem can be tackled in these ways

With Time O(n) and Space O(n)

Make a new array and get the elements from the old array

With Time O(n) and Space O (1)

With Time O(nlogn) and Space O (1)


5 views0 comments