Median of Two Sorted Arrays Solution1

There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).

We can generalize this problem to find kth smallest element in two sorted array.
If we want to find the kth number of the two array. We can check A[k/2-1] and B[k/2-1]:
A[k/2-1] < B[k/2-1] ==> A[0~k/2-1] < kth number, so we can abandon A[0~k/2-1] and go on finding the k-k/2-2 smallest  from A[k/2~] and B;
A[k/2-1] > B[k/2-1] ==> same situation with above
A[k/2-1] = B[k/2-1] ==> Most of the time this is the kth number we are looking for. But not always right for edge cases.
But see the arrays below:
1 2
2 2 4 5 6 6 8 9 10 11
Suppose we want to find the 7th number. We compare A[7/2-1] with B[7/2-1] , but A has a length of 2. So we make a change,we compare A[1] with B[2] and find they are equal. But apparently 2 is not what we want. But 2 is suspicious. So we discard one of the two 2s and go on:
find 5th smallest from the following two arrays
[]
2 4 5 6 6 8 9 10 11
or 
2
4 5 6 6 8 9 10 11