mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 02:53:31 +08:00
Merge pull request #1557 from cezarbbb/Greedy06
添加 0406.根据身高重建队列 Rust版本
This commit is contained in:
@ -290,6 +290,26 @@ var reconstructQueue = function(people) {
|
||||
};
|
||||
```
|
||||
|
||||
### Rust
|
||||
|
||||
```Rust
|
||||
impl Solution {
|
||||
pub fn reconstruct_queue(people: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
|
||||
let mut people = people;
|
||||
people.sort_by(|a, b| {
|
||||
if a[0] == b[0] { return a[1].cmp(&b[1]); }
|
||||
b[0].cmp(&a[0])
|
||||
});
|
||||
let mut que: Vec<Vec<i32>> = Vec::new();
|
||||
que.push(people[0].clone());
|
||||
for i in 1..people.len() {
|
||||
let position = people[i][1];
|
||||
que.insert(position as usize, people[i].clone());
|
||||
}
|
||||
que
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### C
|
||||
```c
|
||||
|
Reference in New Issue
Block a user