Python use bisect


  • 0
    S
    def countSmaller(self, nums):
            """
            :type nums: List[int]
            :rtype: List[int]
            """
            ret = [0 for _ in xrange(len(nums))]
            ns = []
            for i in xrange(len(nums)-1, -1,-1):
                pos = bisect.bisect_left(ns,nums[i])
                ret[i] = pos
                bisect.insort(ns,nums[i])
            return ret
    

Log in to reply
 

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