https://leetcode.com/problems/merge-sorted-array/
1 class Solution { 2 public: 3 void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) { 4 int i=m-1; 5 int j=n-1; 6 int index=m+n-1; 7 while(j>=0) 8 { 9 if(i<0) 10 { 11 nums1[index]=nums2[j]; 12 j--; 13 index--; 14 } 15 else 16 { 17 if(nums1[i]>nums2[j]) 18 { 19 nums1[index]=nums1[i]; 20 i--; 21 } 22 else 23 { 24 nums1[index]=nums2[j]; 25 j--; 26 } 27 index--; 28 29 } 30 } 31 32 } 33 };