LeetCode 53. 最大子数组和

题目描述

🔥 53. 最大子数组和

image-20230305160814847

思路分析

思路描述

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
func maxSubArray(nums []int) int {
	res, total := nums[0], nums[0]
	for i := 1; i < len(nums); i++ {
		if total > 0 {
			total += nums[i]
		} else {
			total = nums[i]
		}
		res = max(res, total)
	}
	return res
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

🍏 点击查看 Java 题解

1
write your code here

相似题目

题目 难度 题解
买卖股票的最佳时机 Easy  
乘积最大子数组 Medium  
数组的度 Easy  
最长湍流子数组 Medium  
本文作者:
本文链接: https://hgnulb.github.io/blog/31655177
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处!