We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 540318b commit c259c7aCopy full SHA for c259c7a
Easy/Maximum Ascending Subarray Sum.java
@@ -1,14 +1,15 @@
1
class Solution {
2
- public int maxAscendingSum(int[] nums) {
3
- int maximumSum = 0;
4
- int idx = 0;
5
- while (idx < nums.length) {
6
- int currSum = nums[idx++];
7
- while (idx < nums.length && nums[idx] > nums[idx - 1]) {
8
- currSum += nums[idx++];
9
- }
10
- maximumSum = Math.max(maximumSum, currSum);
+ public int maxAscendingSum(int[] nums) {
+ int maxSum = 0;
+ int idx = 0;
+ int n = nums.length;
+ while (idx < n) {
+ int currSum = nums[idx++];
+ while (idx < n && nums[idx] > nums[idx - 1]) {
+ currSum += nums[idx++];
+ }
11
+ maxSum = Math.max(maxSum, currSum);
12
13
+ return maxSum;
14
}
- return maximumSum;
15
0 commit comments