public double findMedianSortedArrays(int A[], int B[]) {
        // Start typing your Java solution below
        // DO NOT write main() function

        if (A == null || B == null || (A.length == 0 && B.length == 0)) {
            return 0.0;//hope this will not happen
        } else if (A.length == 0) {
            double result1 = B[(B.length - 1) / 2];
            if (B.length % 2 == 1) {//odd
                return result1;
            } else {
                return (result1 + B[B.length / 2]) / 2.0;
            }
        } else if (B.length == 0) {
            double result1 = A[(A.length - 1) / 2];
            if (A.length % 2 == 1) {//odd
                return result1;
            } else {
                return (result1 + A[A.length / 2]) / 2.0;
            }
        }

        int n = A.length;
        int m = B.length;

        boolean pair = ((n + m) % 2 == 0);
        return helper(A, 0, A.length - 1, B, 0, B.length - 1, (A.length + B.length + 1) / 2 - 1, pair);
    }