Created
April 26, 2020 23:39
-
-
Save yongjhih/b28396b4b0008d4e0cf518e37554f04d 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
class Solution { | |
fun merge(nums1: IntArray, m: Int, nums2: IntArray, n: Int): Unit { | |
var i = m - 1 | |
var j = n - 1 | |
var k = (m + n) - 1 | |
val nums = nums1; | |
while (k >= 0) { | |
if (j >= 0 && (i < 0 || nums1[i] < nums2[j])) { | |
nums[k] = nums2[j] | |
j -= 1 | |
} else { | |
nums[k] = nums1[i] | |
i -= 1 | |
} | |
k -= 1 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment