Skip to content

Instantly share code, notes, and snippets.

@yongjhih
Created April 26, 2020 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yongjhih/b28396b4b0008d4e0cf518e37554f04d to your computer and use it in GitHub Desktop.
Save yongjhih/b28396b4b0008d4e0cf518e37554f04d to your computer and use it in GitHub Desktop.
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