4. Median of Two Sorted Arrays
Contents
https://leetcode.com/problems/median-of-two-sorted-arrays/
https://leetcode.com/problems/median-of-two-sorted-arrays/submissions/708741884/
class Solution {
public:
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
priority_queue<int> q;
for(int i : nums1) q.push(i);
for(int i : nums2) q.push(i);
int popCount = q.size() - 1 >> 1;
bool d = (q.size() % 2 == 0);
while(popCount--) q.pop();
double ans = 0;
ans = q.top(); q.pop();
if(d){
ans = (q.top() + ans) / 2.0;
}
return ans;
}
};