1 class Solution: 2 def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: 3 sorted_nums = sorted(nums) 4 n = len(nums) 5 index = 0 6 dic = {} 7 for i in range(n): 8 cur = sorted_nums[i] 9 if cur not in dic: 10 dic[cur] = index 11 index += 1 12 result = [] 13 for i in range(n): 14 cur = nums[i] 15 result.append(dic[cur]) 16 return result
算法思路:hash