执行用时:20 ms, 在所有 C 提交中击败了54.03%的用户
内存消耗:6.5 MB, 在所有 C 提交中击败了11.17%的用户
二分查找法后续再做
暴力法:复杂度为O(m+n)
double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size)
{double mid = 0.0;if(nums1Size + nums2Size == 0)return mid;if(nums1Size == 0){if(nums2Size % 2 == 0)return (mid = nums2[nums2Size/2] + nums2[nums2Size/2-1])/2;elsereturn (mid = nums2[nums2Size/2]);}if(nums2Size == 0){if(nums1Size % 2 == 0)return (mid = nums1[nums1Size/2] + nums1[nums1Size/2-1])/2;elsereturn (mid = nums1[nums1Size/2]);}int* nums = (int *)malloc(sizeof(int)*(nums1Size+nums2Size+1));int i = 0;int j = 0;int k = 0;while(i < nums1Size && j < nums2Size){if(nums1[i] < nums2[j]){nums[k] = nums1[i];i++;} else{nums[k] = nums2[j];j++;} k++;} while(i < nums1Size)nums[k++] = nums1[i++];while(j < nums2Size)nums[k++] = nums2[j++];nums[k] = '\0'; int m = 0;while(m != k)printf("%d ", nums[m++]);printf("\n");if(k % 2 == 0)return (mid = nums[k/2]+nums[k/2-1])/2;elsereturn (mid = nums[k/2]);return 0;
}