leetcode Median of Two Sorted Arrays
来源:互联网 发布:爱剪辑 for mac 下载 编辑:程序博客网 时间:2024/06/06 02:36
double inline mynext(int A[], int m, int a, int B[], int n, int b){ if (a >= m) return B[b]; if (b >= n) return A[a]; return A[a] < B[b] ? A[a] : B[b];} class Solution {public: double findMedianSortedArrays(int A[], int m, int B[], int n) { int count = 0; int hand = 0; int next = 0; int xxx = (m + n + 1) / 2; int a = 0; int b = 0; while (a<m && b<n && count<xxx) { if (A[a]<B[b]) { hand = A[a]; a++; } else { hand = B[b]; b++; } count++; } if (count >= xxx) { if ((m + n) % 2 == 0) return (hand + mynext(A,m,a,B,n,b)) / 2.0; else return hand; } else if (a<m){ while (count<xxx) { hand = A[a++]; count++; } } else if (b<n){ while (count<xxx) { hand = B[b++]; count++; } } if ((m + n) % 2 == 0) return (hand +mynext(A,m,a,B,n,b)) / 2.0; else return hand; }};
0 0
- LeetCode: Median of Two Sorted Arrays
- LeetCode Median of Two Sorted Arrays
- leetcode 26: Median of Two Sorted Arrays
- Leetcode 4 Median of Two Sorted Arrays
- [Leetcode] 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-004: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 Reverse Nodes in k-Group
- parquet列存储
- 五一巨献,问答有礼,105QB送给IT互联网界的劳动人民
- RubyOnRails在redactor中通过paperclip实现图片上传并编辑的功能
- Java Graphics类的绘图方法
- leetcode Median of Two Sorted Arrays
- Linux Mint 17一周使用体验
- [Java]final关键字的使用 引用类型引用不变 基本类型值不变
- 排序算法及其效率分析(一)内排序
- spark源码分析只: job 全过程
- python_unittest
- [leetcode]Isomorphic Strings
- MFC学习一
- ViewPager的使用方法