Test cases are so week.


  • 0
    K

    My O(n) solution passed all test case on OJ. It would be nice if test case are strict. Here is my O(n) solution

    public class Solution {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int m = nums1.length;
        int n = nums2.length;
        int arr[] = new int[m+n];
        int i=0,j=0,k=0;
        while(i<m && j < n){
            if(nums1[i] < nums2[j]){
                arr[k]=nums1[i];
                i++;k++;
            }else{
                arr[k]=nums2[j];
                j++;k++;
            }
        }
        while(i<m){
            arr[k]=nums1[i];
            k++;i++;
        }
        while(j<n){
            arr[k]=nums2[j];
            k++;j++;
        }
        int len = m+n;
        if(len%2==0)
            return (arr[len/2-1]+arr[len/2]+0.0)/2;
        return arr[len/2]+0.0;
        
    }
    

    }


  • 0
    Y

    My O(m+n) solution also passed the test !


Log in to reply
 

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