Share my easy code


  • -1
    N
    class Solution {
        public:
            double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
                int N = nums1.size() + nums2.size();
                vector<int> merged(N);
                // 归并
                merge(nums1.begin(), nums1.end(),
                        nums2.begin(), nums2.end(),
                        merged.begin());
                // 返回中位数
                if(N&1) return merged[N >> 1]; 
                else return (merged[N >> 1] + merged[(N>>1) - 1]) / 2.0;
            }   
    };
    

Log in to reply
 

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