There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
class Solution {
public:
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
nums1.insert(nums1.begin(),nums2.begin(),nums2.end());
sort(nums1.begin(),nums1.end());
int len = nums1.size();
if (len % 2 == 0)
{
return (nums1[len/2] + nums1[len/2-1])/(double)2;
}
return nums1[len/2];
}
};