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 baf7ed1 commit e43323bCopy full SHA for e43323b
problems/1365.有多少小于当前数字的数字.md
@@ -260,6 +260,22 @@ function smallerNumbersThanCurrent(nums: number[]): number[] {
260
};
261
```
262
263
+### rust
264
+```rust
265
+use std::collections::HashMap;
266
+impl Solution {
267
+ pub fn smaller_numbers_than_current(nums: Vec<i32>) -> Vec<i32> {
268
+ let mut v = nums.clone();
269
+ v.sort();
270
+ let mut hash = HashMap::new();
271
+ for i in 0..v.len() {
272
+ // rust中使用or_insert插入值, 如果存在就不插入,可以使用正序遍历
273
+ hash.entry(v[i]).or_insert(i as i32);
274
+ }
275
+ nums.into_iter().map(|x| *hash.get(&x).unwrap()).collect()
276
277
+}
278
+```
279
280
281
<p align="center">
0 commit comments