bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 88. Merge Sorted Array

88. Merge Sorted Array

Leetcode Solutions

Three Pointers (Start From the End)

  1. Initialize p1 to m - 1, p2 to n - 1, and p to m + n - 1.
  2. While p2 >= 0: a. If p1 >= 0 and nums1[p1] > nums2[p2], place nums1[p1] at nums1[p], decrement p1 and p. b. Otherwise, place nums2[p2] at nums1[p], decrement p2 and p.
  3. If there are still elements in nums2 that haven't been copied (when p1 < 0), copy the remaining elements of nums2 to the beginning of nums1.
UML Thumbnail

Merge and Sort

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...