var findMedianSortedArrays = function(nums1, nums2) {
// 首先我们要明确一点,两个数组都是正序的
// 双指针
let left = 0;
let right = 0;
// 定义合并数组
const mergeArr = [];
// 当其中一个数组遍历到最后时结束
while (left < nums1.length && right < nums2.length) {
if (nums1[left] <= nums2[right]) {
mergeArr.push(nums1[left]);
left++;
} else {
mergeArr.push(nums2[right]);
right++;
}
}
if (right === nums2.length) {
mergeArr.push(...nums1.slice(left))
}
if (left === nums1.length) {
mergeArr.push(...nums2.slice(right))
}
if (mergeArr.length % 2) {
return mergeArr[(mergeArr.length-1) >> 1]
} else {
return (mergeArr[(mergeArr.length-1) >> 1] + mergeArr[((mergeArr.length-1) >> 1) + 1]) / 2
}
};