Find sorted media

problemas a resolver, Técnicos Comments Off on Find sorted media
Sep 082020
import java.util.Arrays;

class Solution {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int [] iArr = addAll(nums1, nums2);
        Arrays.sort(iArr);
        int mid = iArr.length/2;
        return (iArr.length %2 == 0)?(iArr[mid-1] + iArr[mid])/2.0:iArr[mid];
    }
    private int[] addAll(int[] nums1, int[] nums2) {
        int len = nums1.length + nums2.length;
        int[] result = new int[len];
        for(int i=0; i< nums1.length; i++) {
            result[i] = nums1[i];
        }
        for(int i=0; i< nums2.length; i++) {
            result[i+nums1.length] = nums2[i];
        }
        return result;
    }
}
© 2020 Goose Workshop Suffusion theme by Sayontan Sinha