https://leetcode.com/problems/median-of-two-sorted-arrays/
My solution:
double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size){
int size = nums1Size + nums2Size;
int odd = !(size%2);
int i = 0, i1 = 0, i2 = 0;
bool t = false;
int r[2] = {0,0};
while(i < size/2+1){
if(i1 >= nums1Size || (i2 < nums2Size && nums1[i1] > nums2[i2])){
r[t] = nums2[i2];
i2++;
}else{
r[t] = nums1[i1];
i1++;
}
t = odd ? !t : false;
i++;
}
return odd ? (double)(r[0]+r[1])/2 : r[0];
}
Looking for feedback again. The task says to make the complexity O(log (m+n)) but that sort of feels impossible. Just the act of merging the arrays needs to be worse than O(log (m+n)) right? Ending up O((n+m) log (m+n))?
I guess in other languages where they don't think about the merging steps they might see it as log (m+n) just for the searching for median in one merged sorted array?
Or maybe my understanding of O notation is even worse than I feel it already is.