Skip to content

sambedan1/leetcode1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

leetcode1#findMedianSortedArray

class Solution { public double findMedianSortedArrays(int[] nums1, int[] nums2) { int n1 = nums1.length; int n2 = nums2.length; int n = n1 + n2; int[] new_arr = new int[n];

    int i=0, j=0, k=0;

    while (i<=n1 && j<=n2) {
        if (i == n1) {
            while(j<n2) new_arr[k++] = nums2[j++];
            break;
        } else if (j == n2) {
            while (i<n1) new_arr[k++] = nums1[i++];
            break;
        }

        if (nums1[i] < nums2[j]) {
            new_arr[k++] = nums1[i++];
        } else {
            new_arr[k++] = nums2[j++];
        }
    }

    if (n%2==0) return (float)(new_arr[n/2-1] + new_arr[n/2])/2;
    else return new_arr[n/2];
}

}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published