GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • LeetCodeJavascript.com
  • Star on GitHub

This view

  • Original page
  • New address

GeezerVison is showing leetcodejavascript.com — #1800 - Maximum Ascending Subarray Sum - LeetCode JavaScript Solutions

Back to all solutions

#1800 - Maximum Ascending Subarray Sum

Easy • View on LeetCode • View on GitHub
Array

Problem Description

Given an array of positive integers nums, return the maximum possible sum of an ascending subarray in nums.

A subarray is defined as a contiguous sequence of numbers in an array.

A subarray [numsl, numsl+1, ..., numsr-1, numsr] is ascending if for all i where l <= i < r, numsi < numsi+1. Note that a subarray of size 1 is ascending.

Solution

/**
 * @param {number[]} nums
 * @return {number}
 */
var maxAscendingSum = function(nums) {
  let result = nums[0];
  for (let i = 1, max = nums[0]; i < nums.length; i++) {
    max = nums[i] > nums[i - 1] ? max + nums[i] : nums[i];
    result = Math.max(result, max);
  }
  return result;
};
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.