https://leetcode-cn.com/problems/median-of-two-sorted-arrays/
#include<stdio.h>
#include<stdlib.h>
double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size)
{
double num1 = 0;
do
{
if (0 == nums1Size)
{
num1 = -1;
break;
}
if (1 == nums1Size % 2)
{
num1 = *(nums1 + nums1Size / 2);
}
else
{
int tmp1 = nums1[nums1Size / 2];
int tmp2 = nums1[nums1Size / 2 - 1];
num1 = (tmp2 + tmp1) / 2.0;
}
} while (0);
double num2 = 0;
do
{
if (0 == nums2Size)
{
num2 = -1;
break;
}
if (1 == nums2Size % 2)
{
num2 = *(nums2 + nums2Size / 2);
}
else
{
int tmp1 = nums2[nums2Size / 2];
int tmp2 = nums2[nums2Size / 2 - 1];
num2 = (tmp2 + tmp1) / 2.0;
}
} while (0);
if (num1==-1||num2==-1)
{
if (num1 == -1)
{
printf("%f", (num2));
return num2;
}
else
{
printf("%f", (num1));
return num1;
}
}
else
{
printf("%f", (num1 + num2) / 2);
return (num1 + num2) / 2.0;
}
}
int main()
{
int nums1[] = {2,3};
int nums2[] = { 1 };
findMedianSortedArrays(nums1, sizeof(nums1) / sizeof(int), nums2, sizeof(nums2) / sizeof(int));
system("pause");
return 0;
}