MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / maxProduct0

Function maxProduct0

maximum_product_subarray_152/solution.go:29–41  ·  view source on GitHub ↗

First, O(n^2) solution.

(nums []int)

Source from the content-addressed store, hash-verified

27
28// First, O(n^2) solution.
29func maxProduct0(nums []int) int {
30 max := math.MinInt32
31 for i := 0; i < len(nums); i++ {
32 product := nums[i]
33 max = int(math.Max(float64(max), float64(product)))
34 for j := i + 1; j < len(nums); j++ {
35 product *= nums[j]
36 max = int(math.Max(float64(max), float64(product)))
37 }
38 }
39
40 return max
41}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected