Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1919 from NikSWE/go-sln
Browse files Browse the repository at this point in the history
Create: 0088-merge-sorted-array.go
  • Loading branch information
tahsintunan authored Jan 8, 2023
2 parents aba1c2f + 2de2e48 commit 86a0726
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions go/0088-merge-sorted-array.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Time Complexity: O(m + n)
// Space Complexity: O(1)

func merge(nums1 []int, m int, nums2 []int, n int) {
last := m + n - 1
m -= 1
n -= 1

for m >= 0 && n >= 0 {
if nums1[m] > nums2[n] {
nums1[last] = nums1[m]
m -= 1
} else {
nums1[last] = nums2[n]
n -= 1
}
last -= 1
}

for n >= 0 {
nums1[last] = nums2[n]
last -= 1
n -= 1
}
}

0 comments on commit 86a0726

Please sign in to comment.