C++ solution using stl


  • -1
    S

    i am not sure if it is valid, but it passed the tests

    class Solution {
    public:
        double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
            nums1.insert(nums1.end(), nums2.begin(), nums2.end());
    		sort(nums1.begin(), nums1.end());
    
    		size_t len = nums1.size();
    		bool odd = len & 0x1;
    		if (odd)
    		{
    			return nums1[len / 2];
    		}
    		else
    		{
    			return (nums1[len / 2] + nums1[len / 2 - 1]) / (double)2.0;
    		}
        }
    };

  • 6
    G

    It's not O(log(n+m)) but O((n+m)log(n+m)),however.


  • 0
    C
    This post is deleted!

Log in to reply
 

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