Just found a very concise way of solving this problem. please check out here.


  • 0
    G

    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
    int[] nums = new int[nums1.length + nums2.length];
    System.arraycopy(nums1, 0, nums, 0, nums1.length);
    System.arraycopy(nums2, 0, nums, nums1.length, nums2.length);

        Arrays.sort(nums);
        double median = 0.0;
        if(nums.length % 2 == 0) {
            median = nums[nums.length / 2] + nums[nums.length / 2 - 1];
            median = median / 2;
        }
        
        else {
            median = nums[nums.length / 2];
        }
        return median;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.