My C++ solution

  • 0
    class Solution {
        void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
            vector<int> nums(m+n, 0);
            int i,j,k;
            for(i=0, j=0, k=0; i<m && j<n; k++)
                if(nums1[i]<nums2[j]) nums[k] = nums1[i++];
                else nums[k] = nums2[j++];
            while(i<m)  nums[k++] = nums1[i++];
            while(j<n)  nums[k++] = nums2[j++];
            nums1 = nums;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.