Skip to content

Commit

Permalink
Create 05-maximum-split-of-positive-even-integers.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jul 6, 2023
1 parent 00df835 commit 64799be
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 2023/07/05-maximum-split-of-positive-even-integers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
impl Solution {
pub fn maximum_even_split(mut final_sum: i64) -> Vec<i64> {
if final_sum & 1 == 1 {
return vec![];
}
let mut ans = vec![];
let mut i = 2;
while i <= final_sum {
ans.push(i);
final_sum -= i;
i += 2;
}
if final_sum > 0 {
*ans.last_mut().unwrap() += final_sum;
}
ans
}
}

0 comments on commit 64799be

Please sign in to comment.