Simple C++ Solution


  • 0
    M
    class Solution {
    public:
        void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
            vector<int> result;
            int i1 = 0, i2 = 0;
            while (i1 < m || i2 < n) {
                if (i2 >= n || i1 < m && nums1[i1] < nums2[i2]) result.push_back(nums1[i1++]); else result.push_back(nums2[i2++]);
            }
            nums1 = result;
        }
    };
    

Log in to reply
 

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