Python binary search solution

  • 2
    def countSmaller(self, nums):
        :type nums: List[int]
        :rtype: List[int]
        res = []
        s = [] #sorted list
        for n in nums[::-1]:
            i = bisect.bisect_left(s,n)
            #find the index, which means how many numbers in the sorted array are smaller than the cur number
        return res

Log in to reply

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