NOTE
乘积最大子数组
乘积最大子数组 的 LeetCode 解题笔记。
这是历史学习笔记,可能存在过时或不完整的理解。
1. 题目描述
给你一个整数数组 nums ,请你找出数组中乘积最大的连续子数组(该子数组中至少包含一个数字),并返回该子数组所对应的乘积。
2. 思路
- 思路一
- 暴力
- 两层for循环计算出最大的乘积
3. 实现
3.1. 暴力
func maxProduct(nums []int) int {
max := math.MinInt32
for i := 0; i < len(nums); i++ {
res := 1
for j := i; j < len(nums); j++ {
res *= nums[j]
max = Max(max, res)
}
}
return max
}
讨论
使用 GitHub 账号参与讨论,评论会保存在 GitHub Issues 中。在 GitHub 查看