find median of two sorted array
2022年5月1日小于 1 分钟
find median of two sorted array
Question
Given two sorted array of integers, please return the median.
median([1,2],[3,4,5])
// 3
If there are even numbers, return the average.
median([1,2],[3,4])
// 2.5
follow-up
What is the time & space cost of your approach? Could you do better?
Code
/**
* @param {number[]} arr1 - sorted integer array
* @param {number[]} arr2 - sorted integer array
* @returns {number}
*/
function median(arr1, arr2) {
// your code here
}