Wednesday, June 15, 2022

findMedianSortedArrays

 /**

 * @param {number[]} nums1

 * @param {number[]} nums2

 * @return {number}

 */

var findMedianSortedArrays = function(nums1, nums2) {

    var arr = [...nums1, ...nums2]

    const mid = Math.floor(arr.length / 2),

    nums = [...arr].sort((a, b) => a - b);

  return arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;

};

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Generate a catchy title for a collection of newfangled music by making it your own

Write a newfangled code fragment at an earlier stage to use it. Then call another method and make sure their input is the correct one. The s...