LeetCode算法(4)_寻找两个正序数组的中位数
import java.util.Arrays; /* * @lc app=leetcode.cn id=4 lang=java * * [4] 寻找两个正序数组的中位数 */ // @lc code=start class Solution { public double findMedianSortedArrays(int[] nums1, int[] nums2) { int [] list = new int[nums1.length+nums2.length]; System.arraycopy(nums1, 0, list, 0, nums1.length); System.arraycopy(nums2, 0, list, nums1.length, nums2.length); Arrays.sort(list); int sub = list.length/2; return (list.length%2!=0)?list[sub]: (list[sub-1]+list[sub])/2.0f; } } // @lc code=end
LeetCode算法(4)_寻找两个正序数组的中位数
最新推荐文章于 2024-07-08 22:12:26 发布