← All solutions

Merge Sorted Array

June 03, 2025 • Go •array, two pointer, sorting • easy

Problem

  • Merge nums1 and nums2 into a single array sorted in non-decreasing order.

Approach

  • 1. Append the two arrays together
  • 2. Sort

Reflections

Cheated just so I could do a leetcode today. Will redo later

Go Solution

func merge(nums1 []int, m int, nums2 []int, n int)  {
    nums := nums1 
    for _, num := range nums2 {
        nums[m] = num
        m++
    }
    sort.Ints(nums)
    nums1 = nums
}
LeetCode Problem Link