Median of Two Sorted Arrays
来源:互联网 发布:http请求 mac地址 编辑:程序博客网 时间:2024/06/06 19:34
#include<algorithm>using namespace std;class Solution {public: double findMedianSortedArrays(int A[], int m, int B[], int n) { int size = m + n; if(size & 0x1){ return findKth(A, m, B, n, size/2+1); }else{ return (findKth(A, m, B, n, size/2) + findKth(A, m, B, n, size/2+1))/2.0; } } int findKth(int A[], int m, int B[], int n, int k){ if(m > n) return findKth(B, n, A, m, k); if(m==0){ return B[k-1]; } if(k==1){ return min(A[0], B[0]); } int pa = min(m, k/2); int pb = k - pa; if(A[pa-1] < B[pb-1]){ return findKth(A+pa, m-pa, B, n, k-pa); }else if(A[pa-1] > B[pb-1]){ return findKth(A, m, B+pb, n-pb, k-pb); }else return A[pa-1]; } };
0 0
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Median of two sorted arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- median-of-two-sorted-arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Median of Two Sorted Arrays
- Suricata, to 10Gbps and beyond(X86架构)
- 我的大学,我的梦想
- Codeforces Round #252 (Div. 2) 441A Valera and Antique Items
- 怎样测试IEEE NaN 以及其它特殊值?
- 在VS2008下用ACE创建及使用DLL(动态链接库)
- Median of Two Sorted Arrays
- Android中自定义属性的使用
- 第1次实验——NPC问题(回溯算法、聚类分析)
- jquery 根据name属性查找元素
- twisted系列教程十六–twisted守护进程
- 生成高质量的基于矢量的条码专业级的WPF条形码控件
- 【leetcode】Convert Sorted Array to Binary Search Tree
- 黄褐斑的食疗用什么,姬净美效果不错
- iframe里的页面禁止右键事件