Skip to content

Commit f309a81

Browse files
committedFeb 5, 2025
Add solution #1800
1 parent b371c8b commit f309a81

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@
464464
1780|[Check if Number is a Sum of Powers of Three](./1780-check-if-number-is-a-sum-of-powers-of-three.js)|Medium|
465465
1790|[Check if One String Swap Can Make Strings Equal](./1790-check-if-one-string-swap-can-make-strings-equal.js)|Easy|
466466
1791|[Find Center of Star Graph](./1791-find-center-of-star-graph.js)|Easy|
467+
1800|[Maximum Ascending Subarray Sum](./1800-maximum-ascending-subarray-sum.js)|Easy|
467468
1812|[Determine Color of a Chessboard Square](./1812-determine-color-of-a-chessboard-square.js)|Easy|
468469
1817|[Finding the Users Active Minutes](./1817-finding-the-users-active-minutes.js)|Medium|
469470
1832|[Check if the Sentence Is Pangram](./1832-check-if-the-sentence-is-pangram.js)|Easy|
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* 1800. Maximum Ascending Subarray Sum
3+
* https://leetcode.com/problems/maximum-ascending-subarray-sum/
4+
* Difficulty: Easy
5+
*
6+
* Given an array of positive integers nums, return the maximum possible sum of an
7+
* ascending subarray in nums.
8+
*
9+
* A subarray is defined as a contiguous sequence of numbers in an array.
10+
*
11+
* A subarray [numsl, numsl+1, ..., numsr-1, numsr] is ascending if for all i where
12+
* l <= i < r, numsi < numsi+1. Note that a subarray of size 1 is ascending.
13+
*/
14+
15+
/**
16+
* @param {number[]} nums
17+
* @return {number}
18+
*/
19+
var maxAscendingSum = function(nums) {
20+
let result = nums[0];
21+
for (let i = 1, max = nums[0]; i < nums.length; i++) {
22+
max = nums[i] > nums[i - 1] ? max + nums[i] : nums[i];
23+
result = Math.max(result, max);
24+
}
25+
return result;
26+
};

0 commit comments

Comments
 (0)
Please sign in to comment.