OJ Wrong test case


  • 0
    M

    My solution runs in O(log(n+m)). The OJ is returning a wrong test case message :

    public class Solution {
        
        public double findMedianSortedArrays(int[] nums1, int[] nums2) {
            double med1 = getMedian(nums1);
            double med2 = getMedian(nums2);
            return (med1 != 0 && med2 !=0) ? (med1 + med2) / 2 : Math.max(med1, med2);
        }
        
        public double getMedian(int[] a) {
            double result;
            if (a == null || a.length == 0) {
                result = 0;
            } else if (a.length % 2 == 1) {
                result = a[a.length / 2];
            } else {
                double first = a[(a.length / 2) - 1];
                double second = a[a.length / 2];
                result = (first + second) / 2;
            }
            return result;
        }
        
    }
    

    Input:
    [1,1]
    [1,2]
    Output:
    1.25000
    Expected:
    1.00000

    Well...
    1+1 = 2
    2 / 2 = 1.0000

    1+2 = 3
    3 / 2 = 1.5000

    2.5000 / 2 = 1.2500

    Am I missing something here ?


Log in to reply
 

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