C++ Using STL 1 liner


  • 0
    S

    std::merge works as follows:

    merge(
    arr1StartIterator, arr1EndIterator,
    arr2StartIterator, arr2EndIterator,
    placeArrStartIterator,
    comparison);

    Note: placeArr must have enough space

    class Solution {
    public:
        void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
            std::merge(nums2.rbegin(), nums2.rend(), nums1.rbegin()+(nums1.size()-m), nums1.rend(), nums1.rbegin(), std::greater<int>());
        }
    };
    
    

Log in to reply
 

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