Share my simple solution with C++STL algorithm


  • 0
    H

    class Solution {
    public:
    double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
    for (auto iter : nums2)
    {
    nums1.push_back(iter);
    }
    sort(nums1.begin(),nums1.end());
    if (nums1.size() % 2 == 0)return (double)(nums1[nums1.size() / 2-1] + nums1[nums1.size() / 2]) / 2;
    else
    return (double)nums1[(nums1.size() + 1) / 2-1];
    }
    };


Log in to reply
 

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