Skip to content

Commit 422dd1b

Browse files
author
ironartisan
committed
添加1365.有多少小于当前数组的数字python3版本
1 parent 369e55e commit 422dd1b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

problems/1365.有多少小于当前数字的数字.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,19 @@ public int[] smallerNumbersThanCurrent(int[] nums) {
139139
```
140140

141141
Python:
142-
142+
```python
143+
class Solution:
144+
def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:
145+
res = nums[:]
146+
hash = dict()
147+
res.sort() # 从小到大排序之后,元素下标就是小于当前数字的数字
148+
for i, num in enumerate(res):
149+
if num not in hash.keys(): # 遇到了相同的数字,那么不需要更新该 number 的情况
150+
hash[num] = i
151+
for i, num in enumerate(nums):
152+
res[i] = hash[num]
153+
return res
154+
```
143155
Go:
144156

145157
JavaScript:

0 commit comments

Comments
 (0)