Given sorted integer Arrays nums1 and nums2, merge nums2 into nums1 as one sorted Array.
Note:
Assume that nums1 have enough space (size that's greater or equal to m + n) to hold add Itional elements from nums2. The number of elements initialized in nums1and nums2 is m and n respectively.
Problem: Merging B to a on a sequential basis
Parse: Insert Sort, note a array is empty
Not yet AC in doubt!
Class Solution {public: void merge (vector<int>& nums1, int. m, vector<int>& nums2, int n) { in t i = 0; int j = 0; if (m==0) {for (i=0;i<n;i++) nums1[i] = Nums2[i]; } while (I < m && J < N) { if (Nums1[i] <= nums2[j]) { Nums1.insert (Nums1.begin () +i+1, NUMS2[J]); j + +; } i++; } if (i>=m) {for (int k =j;j < n;k++) { Nums1[i] = nums2[k]; }}};
Submission Result:runtime ErrorMore DetailsLast executed input:
[2,0], 1, [1], 1 The question is why [2,0] length is 1?
Merge Sorted Array