Accepted Java solution, not O(log(m+n)) time


  • -3
    V

    public class Solution {
    public double findMedianSortedArrays(int A[], int B[]) {
    int m = A.length;
    int n = B.length;
    double median = 0.0;
    int[] C = new int[m+n];

        for(int i = 0; i < m; i++){
            C[i] = A[i];
        }
        
        for(int j = 0; j < n; j++){
            C[m+j] = B[j];
        }
        
        Arrays.sort(C);
        
        if(C.length % 2 == 0){
            median = ((C[C.length/2] + C[C.length/2 - 1])/2.0);
        }else{
            median = C[C.length/2];
        }
        
        return median;
        
    }
    

    }


Log in to reply
 

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