Untitled
unknown
plain_text
25 days ago
564 B
3
Indexable
Never
class Solution { public: void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) { int j = 0; for (int i = 0; i < m && j < n;) { if(nums1[i + j] <= nums2[j]) i++; else { nums1.insert(nums1.begin() + i + j, nums2[j]); j++; } } while(j < n) { nums1[m + j++] = nums2[j]; } while(nums1.size() > n + m) { nums1.pop_back(); } }
Leave a Comment