Skip to content

Commit 482b088

Browse files
authored
Create 1800-maximum-ascending-subarray-sum.js
1 parent 1da2b88 commit 482b088

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const maxAscendingSum = function(nums) {
6+
let res = -Infinity
7+
8+
const n = nums.length
9+
let cur = 0
10+
for(let i = 0; i < n; i++) {
11+
if(i === 0) cur = nums[i]
12+
if(i > 0) {
13+
if(nums[i] > nums[i - 1]) {
14+
cur += nums[i]
15+
res = Math.max(res, cur)
16+
} else {
17+
res = Math.max(res, cur)
18+
cur = nums[i]
19+
}
20+
}
21+
}
22+
res = Math.max(res, cur)
23+
return res
24+
};

0 commit comments

Comments
 (0)