-
-
Save sumeet/bc95a3944c4a4ee17eb85ac0b1b95251 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <stdio.h> | |
| // [a b c d] | |
| // [a a a b c] | |
| void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n){ | |
| static int nums1_copy[200]; | |
| memcpy(nums1_copy, nums1, m * sizeof(int)); | |
| int input_cursor = 0; | |
| int i = 0; | |
| int j = 0; | |
| while(1) { | |
| if ((i < m) && (j < n)) { | |
| if (nums1_copy[i] < nums2[j]) { | |
| nums1[input_cursor++] = nums1_copy[i++]; | |
| } else { | |
| nums1[input_cursor++] = nums2[j++]; | |
| } | |
| } else if (i < m) { | |
| nums1[input_cursor++] = nums1_copy[i++]; | |
| } else if (j < n) { | |
| nums1[input_cursor++] = nums2[j++]; | |
| } else { | |
| break; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment