leetcode---median-of-two-sorted-arrays---链表
来源:互联网 发布:吴彦祖 知乎 编辑:程序博客网 时间:2024/06/14 17:32
There are two sorted arrays A and B 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)).
class Solution {public: double findMedianSortedArrays(int A[], int m, int B[], int n) { if(!m && !n) return 0; int *a = new int[m+n]; memcpy(a, A, sizeof(int)*m); memcpy(a+m, B, sizeof(int)*n); sort(a, a+m+n); int k = m + n; double mid = k % 2 == 1 ? a[k>>1] : (a[k>>1] + a[(k-1)>>1])/2.0; delete []a; return mid; }};
阅读全文
0 0
- leetcode---median-of-two-sorted-arrays---链表
- 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
- Cg Programming/Unity/Lighting Textured Surfaces光照纹理表面
- 网络流(4)——最小流
- c++学习记录1
- Mybatis框架对log4j日志的支持
- 编写第一个 Hibernate 例子
- leetcode---median-of-two-sorted-arrays---链表
- java 计算过去的时间到今天的时间段
- codeforces883I 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rule
- [LeetCode] 32. Longest Valid Parentheses
- RGB颜色值存储为无符号整数(包括还原RGB)【附完整源码】
- Nginx
- 卷积神经网络的直观解释
- java-继承
- [BZOJ3942][Usaco2015 Feb]Censoring(kmp)