short python solution using binary search, but slow


  • 0
    Y
    import bisect
    class Solution(object):
        def reversePairs(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            seen=[]
            res=0
            for n in nums:
                i=bisect.bisect_right(seen,n<<1)
                res+=(len(seen)-i)
                bisect.insort(seen,n)
            return res
    

Log in to reply
 

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