leetcode 4.Median of Two Sorted Arrays
来源:互联网 发布:怎么阻止软件自动更新 编辑:程序博客网 时间:2024/06/10 05:31
题目
There are two sorted arrays nums1 and nums2 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)).
代码
public class Solution { public double findMedianSortedArrays(int[] nums1, int[] nums2) { double res = 0; int len1 = nums1.length; int len2 = nums2.length; int len = len1 + len2; int[] total = new int[len]; for(int i=0;i<len1;i++){ total[i] = nums1[i]; } for(int j=0;j<len2;j++){ total[len1+j] = nums2[j]; } Arrays.sort(total); if(len%2==0){ res = (double) (total[len/2-1] + total[len/2])/2; }else{ res = total[len/2]; } return res; }}
0 0
- [LeetCode]4.Median of Two Sorted Arrays
- LeetCode 4. Median of Two Sorted Arrays
- LeetCode --- 4. Median of Two Sorted Arrays
- [Leetcode] 4. Median of Two Sorted Arrays
- [LeetCode]4.Median of Two Sorted Arrays
- 【leetcode】4. Median of Two Sorted Arrays
- Leetcode-4.Median of Two Sorted Arrays
- LeetCode-4.Median of Two Sorted Arrays
- Leetcode 4. Median of Two Sorted Arrays
- leetcode 4. Median of Two Sorted Arrays
- LeetCode 4. Median of Two Sorted Arrays
- Leetcode 4. Median of Two Sorted Arrays
- Leetcode 4. Median of Two Sorted Arrays
- [leetcode]4. Median of Two Sorted Arrays
- LeetCode-4.Median of Two Sorted Arrays
- [LeetCode]4. Median of Two Sorted Arrays
- leetCode 4. Median of Two Sorted Arrays
- Leetcode 4. Median of Two Sorted Arrays
- 第12周项目4-String类的构造
- 停止并重新开始Activity
- vector中insert()的用法详解
- 欢迎使用CSDN-markdown编辑器
- 遍历Map的四种方法
- leetcode 4.Median of Two Sorted Arrays
- Java基础--递归算法
- jQuery.Validate验证库的使用
- lua 中 loadstring 应用(用于游戏中解析字符串公式)
- 常用docker命令,及一些坑
- 怎么才能线程安全?
- 重新创建Activity
- appium 环境搭建
- Java设计模式(十一):外观模式(门面模式)Facade