問題
https://leetcode.com/problems/median-of-two-sorted-arrays/
解いた
# @param {Integer[]} nums1 # @param {Integer[]} nums2 # @return {Float} def find_median_sorted_arrays(nums1, nums2) nums = (nums1 + nums2).sort result = 0 if nums.length.zero? return 0 end if nums.length == 1 return nums.first end if nums.length.even? index = nums.length / 2 result = (nums[index - 1] + nums[index]).to_f / 2 else index = nums.length / 2 result = nums[index] end result end
結果