Why the answer is not the same


  • 0
    B
    nums1[len(nums1):]=nums2
        tlist =sorted(nums1)
    
        print(tlist)
        tlen = len(tlist)
        result = 0
        if tlen % 2 == 0:
            result = (tlist[(int)(tlen / 2) - 1] + tlist[(int)(tlen / 2)]) / 2
           
        else:
            result = tlist[(int)(tlen / 2)]
        return result
    

    I get the answer 2.5 on my machine, but when I run the code in the website, it got the answer 2?


  • 0
    B

    it seems that the version of the python used in this website is down to 3, so when use "/" it got the integer part. Muttiply the answer with 1.0 can solve the problem.


Log in to reply
 

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