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 c599da7 commit 94c41c9Copy full SHA for 94c41c9
rust/0179-largest-number.rs
@@ -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