6ms very simple C++ solution


  • -6
    D
    #include <algorithm>
    
    class Solution {
    public:
        void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
            
            if(n == 0) 
                return;
    
            for(int i = m; i < m+n; i++)
                nums1[i] = nums2[i-m];
            
            if(m == 0)
                return;
                
            std::sort(nums1.begin(),nums1.end());
            
            
        }
    };

Log in to reply
 

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