1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 17:56:55 +02:00

rs: add «2971. Find Polygon With the Largest Perimeter»

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2024-02-15 23:19:43 +01:00
parent 088cfb5560
commit 85d4d8d9ab
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,20 @@
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
}
}