leetcode Median of Two Sorted Arrays
2015-05-21 00:53
375 查看
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)).
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]; } };
相关文章推荐
- [leetcode]Median of Two Sorted Arrays
- 25th Feb: LeetCode 4 Median of Two Sorted Arrays
- leetcode | Median of Two Sorted Arrays 寻找2个有序数组中第k大的值
- Median of Two Sorted Arrays - LeetCode 4
- Leetcode 4. Median of Two Sorted Arrays
- 《leetCode》:Median of Two Sorted Arrays
- leetcode 刷题日记——Median of Two Sorted Arrays
- LeetCode 4_Median of Two Sorted Arrays
- leetcode python - Median of Two Sorted Arrays
- leetcode 2 MEDIAN OF TWO SORTED ARRAYS
- 刷LeetCode(4)——Median of Two Sorted Arrays
- LeetCode之Median Of Two Sorted Arrays
- [LeetCode] Median of Two Sorted Arrays 解题报告
- 【LeetCode】Median of Two Sorted Arrays
- leetcode - Median of Two Sorted Arrays
- leetcode Median of Two Sorted Arrays
- [LeetCode] Median of Two Sorted Arrays
- LeetCode 4 Median of Two Sorted Arrays
- [leetcode] median of two sorted arrays[C++ vector版本]
- [LeetCode题解004]Median of Two Sorted Arrays