A simple revolution (c++)


  • 0
    W

    double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
    double a;
    vector<int> num;
    for(size_t i=0;i<nums1.size();++i)
    {
    num.push_back(nums1[i]);
    }
    for(size_t i=0;i<nums2.size();++i)
    {
    num.push_back(nums2[i]);
    }
    sort(num.begin(),num.end());
    int m=nums1.size();
    int n=nums2.size();
    if((m+n)%2==0)
    a=(double)(num[(m+n)/2]+num[(m+n)/2-1])/2;
    else
    a=num[(m+n)/2];
    return a;
    }


Log in to reply
 

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