Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions leetcode/1701-1800/1800.Maximum-Ascending-Subarray-Sum/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
# [1800.Maximum Ascending Subarray Sum][title]

> [!WARNING|style:flat]
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)

## 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**.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: nums = [10,20,30,5,10,50]
Output: 65
Explanation: [5,10,50] is the ascending subarray with the maximum sum of 65.
```

## 题意
> ...

## 题解
**Example 2:**

### 思路1
> ...
Maximum Ascending Subarray Sum
```go
```
Input: nums = [10,20,30,40,50]
Output: 150
Explanation: [10,20,30,40,50] is the ascending subarray with the maximum sum of 150.
```

**Example 3:**

```
Input: nums = [12,17,15,13,10,11,12]
Output: 33
Explanation: [10,11,12] is the ascending subarray with the maximum sum of 33.
```

## 结语

Expand Down
17 changes: 15 additions & 2 deletions leetcode/1701-1800/1800.Maximum-Ascending-Subarray-Sum/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
package Solution

func Solution(x bool) bool {
return x
func Solution(nums []int) int {
sum := 0
pre := 0
ans := 0
for _, n := range nums {
if n > pre {
sum += n
pre = n
continue
}
ans = max(ans, sum)
sum = n
pre = n
}
return max(ans, sum)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
expect bool
inputs []int
expect int
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", []int{10, 20, 30, 5, 10, 50}, 65},
{"TestCase2", []int{10, 20, 30, 40, 50}, 150},
{"TestCase3", []int{12, 17, 15, 13, 10, 11, 12}, 33},
}

// 开始测试
Expand All @@ -30,10 +30,10 @@ func TestSolution(t *testing.T) {
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading