Skip to content

Commit

Permalink
Create 27-maximum-subarray-sum-with-one-deletion.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 27, 2023
1 parent 6aec00d commit b7a1865
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 2023/06/27-maximum-subarray-sum-with-one-deletion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
impl Solution {
pub fn maximum_sum(arr: Vec<i32>) -> i32 {
let (mut dp0, mut dp1, mut ans) = (arr[0], 0, arr[0]);
for i in 1..arr.len() {
dp1 = dp0.max(dp1 + arr[i]);
dp0 = dp0.max(0) + arr[i];
ans = ans.max(dp0).max(dp1);
}
ans
}
}

0 comments on commit b7a1865

Please sign in to comment.