LeetCode每日一练【4】

LeetCode每日一练

median-of-two-sorted-arrays

/*
 * @Author: fox
 * @Date: 2022-04-21 05:10:43
 * @LastEditors: fox
 * @LastEditTime: 2022-04-21 05:55:39
 * @Description: https://leetcode.com/problems/median-of-two-sorted-arrays/
 */
const findMedianSortedArrays = (nums1, nums2) => {
    const nums = [...nums1, ...nums2].sort((a, b) => {
        return a - b;
    });
    const length = nums.length;
    const median = Math.floor(length / 2);
    return length % 2 === 1 ? nums[median] : (nums[median] + nums[median - 1]) / 2;
};
posted @ 2022-04-21 05:57  白い故雪  阅读(13)  评论(0编辑  收藏  举报