Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94c41c9

Browse files
committed
Added 0179-largest-number.rs
1 parent c599da7 commit 94c41c9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

rust/0179-largest-number.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::cmp::Ordering;
2+
3+
impl Solution {
4+
pub fn largest_number(nums: Vec<i32>) -> String {
5+
let mut ans = String::new();
6+
let mut nums = nums;
7+
let mut strs = nums.into_iter().map(|e| e.to_string()).collect::<Vec<String>>();
8+
strs.sort_by(|a, b| {
9+
let a_first = a.clone() + &*b;
10+
let b_first = b.clone() + &*a;
11+
b_first.cmp(&a_first)
12+
});
13+
for num in strs {
14+
if ans == "0" && num == "0" {continue}
15+
ans.push_str(&*num.to_string())
16+
}
17+
18+
ans
19+
}
20+
}

0 commit comments

Comments
 (0)