Skip to content

Commit 305c9da

Browse files
authored
Create 1186-maximum-subarray-sum-with-one-deletion.js
1 parent e1a42d6 commit 305c9da

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number[]} arr
3+
* @return {number}
4+
*/
5+
const maximumSum = function(arr) {
6+
const n = arr.length
7+
let d1 = arr[0],
8+
d2 = arr[0],
9+
best = arr[0]
10+
for (let i = 1; i < n; ++i) {
11+
d2 = Math.max(d2 + arr[i], Math.max(d1, arr[i]))
12+
d1 = Math.max(d1 + arr[i], arr[i])
13+
best = Math.max(d2, best)
14+
}
15+
return best
16+
}

0 commit comments

Comments
 (0)