Created
December 26, 2018 08:31
-
-
Save Sherlock-Holo/ec00fd9b594669a95628a2498cba295a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func merge(nums1 []int, m int, nums2 []int, n int) { | |
if n == 0 { | |
return | |
} | |
if m == 0 { | |
copy(nums1, nums2) | |
return | |
} | |
j := m - 1 | |
k := n - 1 | |
for i := len(nums1) - 1; i >= 0; i-- { | |
if nums1[j] > nums2[k] { | |
nums1[i] = nums1[j] | |
j-- | |
if j < 0 { | |
copy(nums1, nums2[:k+1]) | |
return | |
} | |
} else { | |
nums1[i] = nums2[k] | |
k-- | |
if k < 0 { | |
return | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment