from typing import List


def smallerNumbersThanCurrent0(nums: List[int]) -> List[int]:
    """
    排序与映射：排序之后，其实每一个数值的下标就代表这前面有几个比它小的了。
    https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/solution/1365-you-duo-shao-xiao-yu-dang-qian-shu-zi-de-s-35/    """
    length = len(nums)
    if length <= 0: return []

    #排序
    nums2 = sorted(nums)

    #逆序哈希(相同元素取最左面的数值和下标)
    map = {}
    for i in range(length - 1, -1, -1):
        map[nums2[i]] = i

    count = [0] * length
    for i in range(length):
        count[i] = map[nums[i]]

    return count