代码
double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size){
int len = nums1Size+nums2Size;
int mark[len];
int i = 0;
int n1=0,n2=0;
while (n1<nums1Size&&n2<nums2Size)
{
if(nums1[n1]<nums2[n2]){
mark[i] = nums1[n1];
n1++;
}
else{
mark[i] = nums2[n2];
n2++;
}
i++;
}
while(n1<nums1Size){
mark[i++]=nums1[n1++];
}
while (n2<nums2Size)
{
mark[i++]=nums2[n2++];
}
for ( i = 0; i < len; i++)
{
printf("%d ",mark[i]);
}
printf("\n");
if(len%2==0)
return (mark[len/2]+mark[len/2-1])/2.0;
else
return mark[len/2]/1.0;
return 0;
}
|