Skip to content

Instantly share code, notes, and snippets.

@VallarasuS
Last active March 16, 2023 04:54
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 VallarasuS/65a67b942210fb8127ce48e6104f0bfa to your computer and use it in GitHub Desktop.
Save VallarasuS/65a67b942210fb8127ce48e6104f0bfa to your computer and use it in GitHub Desktop.
class Solution {
public void merge(int[] nums1, int m, int[] nums2, int n) {
int capacity = m + n;
for(int i = capacity -1; i >= 0; i--) {
if(n < 1) {
return;
}
if(m < 1) {
nums1[i] = nums2[--n];
continue;
}
if(nums1[m - 1] > nums2[n - 1]) {
nums1[i] = nums1[--m];
}
else {
nums1[i] = nums2[--n];
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment