Skip to content

Commit 77e51e0

Browse files
committedFeb 6, 2022
feat: add solutions to lcof problem: No.45
面试题45. 把数组排成最小的数
1 parent 24fe7cd commit 77e51e0

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
 

‎lcof/面试题45. 把数组排成最小的数/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,27 @@ public:
116116
};
117117
```
118118
119+
### **TypeScript**
120+
121+
```ts
122+
function minNumber(nums: number[]): string {
123+
return nums
124+
.sort((a, b) => Number(`${a}${b}`) - Number(`${b}${a}`))
125+
.join('');
126+
}
127+
```
128+
129+
### **Rust**
130+
131+
```rust
132+
impl Solution {
133+
pub fn min_number(mut nums: Vec<i32>) -> String {
134+
nums.sort_by(|a, b| format!("{}{}", a, b).cmp(&format!("{}{}", b, a)));
135+
nums.iter().map(|num| num.to_string()).collect()
136+
}
137+
}
138+
```
139+
119140
### **...**
120141

121142
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
impl Solution {
2+
pub fn min_number(mut nums: Vec<i32>) -> String {
3+
nums.sort_by(|a, b| format!("{}{}", a, b).cmp(&format!("{}{}", b, a)));
4+
nums.iter().map(|num| num.to_string()).collect()
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function minNumber(nums: number[]): string {
2+
return nums
3+
.sort((a, b) => Number(`${a}${b}`) - Number(`${b}${a}`))
4+
.join('');
5+
}

0 commit comments

Comments
 (0)
Please sign in to comment.