mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
添加1365.有多少小于当前数组的数字python3版本
This commit is contained in:
@ -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:
|
||||
|
Reference in New Issue
Block a user