Skip to content

Commit 7c170a6

Browse files
committed
feat: add solutions to lc problem: No.2418
No.2418.Sort the People
1 parent 9e9d7e7 commit 7c170a6

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

solution/2400-2499/2418.Sort the People/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,24 @@ func sortPeople(names []string, heights []int) []string {
130130
### **TypeScript**
131131

132132
```ts
133+
function sortPeople(names: string[], heights: number[]): string[] {
134+
return names
135+
.map<[string, number]>((s, i) => [s, heights[i]])
136+
.sort((a, b) => b[1] - a[1])
137+
.map(([v]) => v);
138+
}
139+
```
140+
141+
### **Rust**
133142

143+
```rust
144+
impl Solution {
145+
pub fn sort_people(names: Vec<String>, heights: Vec<i32>) -> Vec<String> {
146+
let mut combine: Vec<(String, i32)> = names.into_iter().zip(heights.into_iter()).collect();
147+
combine.sort_by(|a, b| b.1.cmp(&a.1));
148+
combine.iter().map(|s| s.0.clone()).collect()
149+
}
150+
}
134151
```
135152

136153
### **...**

solution/2400-2499/2418.Sort the People/README_EN.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,24 @@ func sortPeople(names []string, heights []int) []string {
116116
### **TypeScript**
117117

118118
```ts
119+
function sortPeople(names: string[], heights: number[]): string[] {
120+
return names
121+
.map<[string, number]>((s, i) => [s, heights[i]])
122+
.sort((a, b) => b[1] - a[1])
123+
.map(([v]) => v);
124+
}
125+
```
126+
127+
### **Rust**
119128

129+
```rust
130+
impl Solution {
131+
pub fn sort_people(names: Vec<String>, heights: Vec<i32>) -> Vec<String> {
132+
let mut combine: Vec<(String, i32)> = names.into_iter().zip(heights.into_iter()).collect();
133+
combine.sort_by(|a, b| b.1.cmp(&a.1));
134+
combine.iter().map(|s| s.0.clone()).collect()
135+
}
136+
}
120137
```
121138

122139
### **...**
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
impl Solution {
2+
pub fn sort_people(names: Vec<String>, heights: Vec<i32>) -> Vec<String> {
3+
let mut combine: Vec<(String, i32)> = names.into_iter().zip(heights.into_iter()).collect();
4+
combine.sort_by(|a, b| b.1.cmp(&a.1));
5+
combine.iter().map(|s| s.0.clone()).collect()
6+
}
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function sortPeople(names: string[], heights: number[]): string[] {
2+
return names
3+
.map<[string, number]>((s, i) => [s, heights[i]])
4+
.sort((a, b) => b[1] - a[1])
5+
.map(([v]) => v);
6+
}

0 commit comments

Comments
 (0)