315. Count of Smaller Numbers After Self (Hard) - TengnanYao/daily_leetcode GitHub Wiki

class Solution(object):
    def countSmaller(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        result, arr = [0] * len(nums), []
        for i in range(len(nums) - 1, -1, -1):
            index = bisect_left(arr, nums[i])
            result[i] = index
            arr.insert(index, nums[i])
        return result