Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fe137e0

Browse files
Merge pull request youngyangyang04#2443 from gdstzmy/master
Update 0053.最大子序和.md
2 parents 095242f + df8878b commit fe137e0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎problems/0053.最大子序和.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,25 @@ class Solution:
230230

231231
```
232232
### Go
233+
贪心法
234+
```go
235+
func maxSubArray(nums []int) int {
236+
max := nums[0]
237+
count := 0
233238

239+
for i := 0; i < len(nums); i++{
240+
count += nums[i]
241+
if count > max{
242+
max = count
243+
}
244+
if count < 0 {
245+
count = 0
246+
}
247+
}
248+
return max
249+
}
250+
```
251+
动态规划
234252
```go
235253
func maxSubArray(nums []int) int {
236254
maxSum := nums[0]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /