go: add «2874. Maximum Value of an Ordered Triplet II»
URL: https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-ii/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
b6c2e213a1
commit
b8bdec306c
1 changed files with 13 additions and 0 deletions
13
go/maximum-value-of-an-ordered-triplet-ii.go
Normal file
13
go/maximum-value-of-an-ordered-triplet-ii.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package main
|
||||
|
||||
func maximumTripletValue(nums []int) int64 {
|
||||
var maxValue, imax, dmax int64 = 0, 0, 0
|
||||
for _, x := range nums {
|
||||
num := int64(x)
|
||||
maxValue = max(maxValue, dmax*num)
|
||||
dmax = max(dmax, imax-num)
|
||||
imax = max(imax, num)
|
||||
}
|
||||
|
||||
return maxValue
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue