Участник:Taranov srg/Small counting

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/count-of-smaller-numbers-after-self/submissions/

Python3

class Solution:
    import bisect
 
 
    def countSmaller(self, nums: List[int]) -> List[int]:
        sorted_nums, result = [], [0] * len(nums)
        for i in range(len(nums)-1, -1, -1):
            new_index = bisect.bisect_left(sorted_nums, nums[i])
            result[i] = new_index
            sorted_nums.insert(new_index, nums[i])
        return result