mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 01:49:41 +01:00
21 lines
373 B
Rust
21 lines
373 B
Rust
|
impl Solution {
|
||
|
pub fn largest_perimeter(mut nums: Vec<i32>) -> i64 {
|
||
|
nums.sort();
|
||
|
|
||
|
let mut sum: i64 = 0;
|
||
|
let mut max_perimeter: i64 = -1;
|
||
|
|
||
|
for x in &nums {
|
||
|
let x = i64::from(*x);
|
||
|
|
||
|
if x < sum {
|
||
|
max_perimeter = x + sum;
|
||
|
}
|
||
|
|
||
|
sum += x;
|
||
|
}
|
||
|
|
||
|
max_perimeter
|
||
|
}
|
||
|
}
|