leetcode getting different result than my IDE?

  • 0

    i get 2.5 in my IDE (intellij) but 2 on leetcode and i dont know why?

    class Solution(object):
        def findMedianSortedArrays(self, nums1, nums2):
            :type nums1: List[int]
            :type nums2: List[int]
            :rtype: float
            nums3 = nums1 + nums2
            sortedList = sorted(nums3)
            listLength = len(nums3)
            halfLength = int(listLength/2)
            if listLength ==1:
                return nums3[0]
            elif listLength%2==0:
                return (sortedList[halfLength]+ nums3[halfLength-1])/2
                return sortedList[halfLength]
    attempt = Solution()
    print(attempt.findMedianSortedArrays([1, 2], [3, 4]))

  • 0

    @AlanAhsanian This is because LeetCode supports Python 2, not Python 3. Met the same problem and just realized the difference. so in your case you need to add "float()" as below...

    return float(sortedList[halfLength]+ nums3[halfLength-1])/2

Log in to reply

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