添加1365.有多少小于当前数组的数字python3版本

This commit is contained in:
ironartisan
2021-08-09 22:07:43 +08:00
parent 369e55ed67
commit 422dd1bcc1

View File

@ -139,7 +139,19 @@ public int[] smallerNumbersThanCurrent(int[] nums) {
```
Python
```python
class Solution:
def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:
res = nums[:]
hash = dict()
res.sort() # 从小到大排序之后,元素下标就是小于当前数字的数字
for i, num in enumerate(res):
if num not in hash.keys(): # 遇到了相同的数字,那么不需要更新该 number 的情况
hash[num] = i
for i, num in enumerate(nums):
res[i] = hash[num]
return res
```
Go
JavaScript