JAVASCRIPT
Median of Two Sorted Arrays
const findMedianSortedArrays = (num1, num2) => {
let total = num1.length + num2.length
let arr = []
if (total === 1) {
return num1.length == 1 ? num1[0] : num2[0];
}
let arr_len = total % 2 == 0 ? (total) / 2 + 1 : Math.ceil(total / 2);
let i = 0
let j = 0
while (arr.length < arr_len) {
if (i < num1.length && j < num2.length) {
if (num1[i] <= num2[j]) {
arr.push(num1[i])
i++
} else {
arr.push(num2[j])
j++
}
} else if (i >= num1.length) {
arr.push(num2[j])
j++
} else {
arr.push(num1[i])
i++
}
}
return total % 2 == 0 ? (arr[arr.length - 1] + arr[arr.length - 2]) / 2 : arr[arr.length - 1];
}
Median of Two Sorted Arrays
class Solution {
public:
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
}
};
Median of Two Sorted Arrays
class Solution {
public double findMedianSortedArrays(int[] nums1, int[] nums2) {
}
}
Median of Two Sorted Arrays
double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size){
}
Median of Two Sorted Arrays
public class Solution {
public double FindMedianSortedArrays(int[] nums1, int[] nums2) {
}
}
Median of Two Sorted Arrays
/**
* @param {number[]} nums1
* @param {number[]} nums2
* @return {number}
*/
var findMedianSortedArrays = function(nums1, nums2) {
};
Median of Two Sorted Arrays
# @param {Integer[]} nums1
# @param {Integer[]} nums2
# @return {Float}
def find_median_sorted_arrays(nums1, nums2)
end
Median of Two Sorted Arrays
class Solution {
func findMedianSortedArrays(_ nums1: [Int], _ nums2: [Int]) -> Double {
}
}
Median of Two Sorted Arrays
class Solution {
/**
* @param Integer[] $nums1
* @param Integer[] $nums2
* @return Float
*/
function findMedianSortedArrays($nums1, $nums2) {
}
}
Median of Two Sorted Arrays
function findMedianSortedArrays(nums1: number[], nums2: number[]): number {
};