4. Median of Two Sorted Arrays
程序员文章站
2022-03-03 09:00:41
...
class Solution {
public static double findMedianSortedArrays(int[] nums1, int[] nums2) {
int i=0,j=0,k=0;
int len1=nums1.length;
int len2=nums2.length;
double rem;
int [] result=new int[len1+len2];
while(i<len1&&j<len2)
{
if(nums1[i]<=nums2[j])
{
result[k++]=nums1[i++];
}
else
{
result[k++]=nums2[j++];
}
}
while(i<nums1.length)
{
result[k++]=nums1[i++];
}
while(j<nums2.length)
{
result[k++]=nums2[j++];
}
if(result.length%2==0)
{
rem=(double)(result[result.length/2]+result[result.length/2-1])/2;
}
else
{
rem=result[result.length/2];
}
return rem;
}
}
推荐阅读
-
【LeetCode】4. Median of Two Sorted Arrays
-
1.Merge Two Sorted Arrays. py/合并排序有序数列
-
LeetCode 4. 两个排序数组的中位数 Median of Two Sorted Arrays
-
算法练习(3):Median of Two Sorted Arrays
-
LeetCode算法系列:4、Median of Two Sorted Arrays
-
4. Median of Two Sorted Arrays
-
4. Median of Two Sorted Arrays
-
【leetcode】4. Median of Two Sorted Arrays
-
【leetcode阿里题库】4. Median of Two Sorted Arrays
-
Median of Two Sorted Arrays(C++)