Question -- Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
The overall run time complexity should be O(log (m+n)).
My Method
class Solution {
public double sum(int[] nums){
int summ = 0;
for(int i = 0;i<nums.length;i++){
summ = summ + nums[i];
}
return sum/nums.length;
}
public double findMedianSortedArrays(int[] nums1, int[] nums2) {
int j = 0;
if(nums1.length>=nums2.length){
int nums1[] = new nums1[nums1.length + nums2.length];
for(int i =0;i<nums1.length;i++) if(nums1[i]==0) {
nums1[i] = nums2[j];
j++;
}
}else
{
nums2[] = new nums2[nums1.length + nums2.length];
for(int i =0;i<nums2.length;i++) if(nums2[i]==0) {
nums2[i] = nums1[j];
j++;
}
if(nums2.length%2==0){
return nums2[nums2.length/2] + nums2[nums2.length/2 - 1];
} else
{
return sum();
}
}
}
}