Median of Two Sorted Arrays
<p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>

<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [1,3], nums2 = [2]
<strong>Output:</strong> 2.00000
<strong>Explanation:</strong> merged array = [1,2,3] and median is 2.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [1,2], nums2 = [3,4]
<strong>Output:</strong> 2.50000
<strong>Explanation:</strong> merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>nums1.length == m</code></li>
	<li><code>nums2.length == n</code></li>
	<li><code>0 &lt;= m &lt;= 1000</code></li>
	<li><code>0 &lt;= n &lt;= 1000</code></li>
	<li><code>1 &lt;= m + n &lt;= 2000</code></li>
	<li><code>-10<sup>6</sup> &lt;= nums1[i], nums2[i] &lt;= 10<sup>6</sup></code></li>
</ul>
Array; Binary Search; Divide and Conquer
int findKth(int* nums1, int m, int i, int* nums2, int n, int j, int k) {
    if (i >= m)
        return nums2[j + k - 1];
    if (j >= n)
        return nums1[i + k - 1];
    if (k == 1)
        return nums1[i] < nums2[j] ? nums1[i] : nums2[j];

    int p = k / 2;

    int x = (i + p - 1 < m) ? nums1[i + p - 1] : INT_MAX;
    int y = (j + p - 1 < n) ? nums2[j + p - 1] : INT_MAX;

    if (x < y)
        return findKth(nums1, m, i + p, nums2, n, j, k - p);
    else
        return findKth(nums1, m, i, nums2, n, j + p, k - p);
}

double findMedianSortedArrays(int* nums1, int m, int* nums2, int n) {
    int total = m + n;
    int a = findKth(nums1, m, 0, nums2, n, 0, (total + 1) / 2);
    int b = findKth(nums1, m, 0, nums2, n, 0, (total + 2) / 2);
    return (a + b) / 2.0;
}
