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 c6fadbd commit bb1dd8dCopy full SHA for bb1dd8d
problems/1365.有多少小于当前数字的数字.md
@@ -152,7 +152,35 @@ class Solution:
152
res[i] = hash[num]
153
return res
154
```
155
+
156
Go:
157
+```go
158
+func smallerNumbersThanCurrent(nums []int) []int {
159
+ // map,key[数组中出现的数] value[比这个数小的个数]
160
+ m := make(map[int]int)
161
+ // 拷贝一份原始数组
162
+ rawNums := make([]int,len(nums))
163
+ copy(rawNums,nums)
164
+ // 将数组排序
165
+ sort.Ints(nums)
166
+ // 循环遍历排序后的数组,值为map的key,索引为value
167
+ for i,v := range nums {
168
+ _,contains := m[v]
169
+ if !contains {
170
+ m[v] = i
171
+ }
172
173
174
+ // 返回值结果
175
+ result := make([]int,len(nums))
176
+ // 根据原始数组的位置,存放对应的比它小的数
177
+ for i,v := range rawNums {
178
+ result[i] = m[v]
179
180
181
+ return result
182
+}
183
+```
184
185
JavaScript:
186
```javascript
0 commit comments