We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 369e55e commit 422dd1bCopy full SHA for 422dd1b
problems/1365.有多少小于当前数字的数字.md
@@ -139,7 +139,19 @@ public int[] smallerNumbersThanCurrent(int[] nums) {
139
```
140
141
Python:
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
+```
155
Go:
156
157
JavaScript:
0 commit comments