LeetCode【4】寻找两个正序数组中位数

题目:

LeetCode【4】寻找两个正序数组中位数_第1张图片

思路:
https://blog.csdn.net/a1111116/article/details/115033098

代码:

    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int[] ints = Arrays.copyOf(nums1, nums1.length + nums2.length);

        System.arraycopy(nums2, 0, ints, nums1.length, nums2.length);

        Arrays.sort(ints);

        int n = ints.length;

        int test = n / 2;
        if (n % 2 == 0) {
            return (ints[test] + ints[test - 1]) / 2.0;
        } else {
            return ints[(n - 1) / 2];
        }
    }

你可能感兴趣的:(leetcode,算法,职场和发展)