class Solution { public: double findMedianSortedArrays(vector<int> &nums1, vector<int> &nums2) { int nums1Size = nums1.size(); int nums2Size = nums2.size(); int na = nums1Size + nums2Size; int *ns = (int *)malloc(4 * na); int i = 0, j = 0, d = 0; int m = na / 2 + 1; while (d < m) { int n; if (i < nums1Size && j < nums2Size) { n = (nums1[i] < nums2[j]) ? nums1[i++] : nums2[j++]; } else if (i < nums1Size) { n = nums1[i++]; } else if (j < nums2Size) { n = nums2[j++]; } ns[d++] = n; } if (na % 2) { return ns[d - 1]; } return (ns[d - 1] + ns[d - 2]) / 2.0; } };