严氏北美IT公司面试真题汇总和解答论坛
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Merge Two Sorted Array

Go down

Merge Two Sorted Array Empty Merge Two Sorted Array

Post by Admin Sat Oct 21, 2017 4:52 pm

public static void merge(int[] nums1, int m, int[] nums2, int n) {
int i = m - 1;
int j = n - 1;
int k = m + n - 1;
while (k >= 0) {
if (j < 0 || (i >= 0 && nums1[i] > nums2[j]))
nums1[k--] = nums1[i--];
else
nums1[k--] = nums2[j--];
}
}


Admin
Admin

Posts : 124
Join date : 2017-10-21

https://csinterviewquestions.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum