We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b557880 commit d0a060dCopy full SHA for d0a060d
solution/0088.Merge Sorted Array/Solution.go
@@ -0,0 +1,20 @@
1
+func merge(nums1 []int, m int, nums2 []int, n int) {
2
+ ret := make([]int, m+n)
3
+ copy(ret, nums1[:m])
4
+ p0, p1, p2 := 0, 0, 0
5
+ for ; p1 < m && p2 < n; p0++ {
6
+ if nums1[p1] >= nums2[p2] {
7
+ ret[p0] = nums2[p2]
8
+ p2++
9
+ } else if nums1[p1] < nums2[p2] {
10
+ ret[p0] = nums1[p1]
11
+ p1++
12
+ }
13
14
+ if p1 < m {
15
+ copy(nums1, append(ret[:p0], nums1[p1:m]...))
16
17
+ if p2 < n {
18
+ copy(nums1, append(ret[:p0], nums2[p2:]...))
19
20
+}
0 commit comments