go: add «2873. Maximum Value of an Ordered Triplet I»
URL: https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
5c40a25702
commit
b6c2e213a1
1 changed files with 14 additions and 0 deletions
14
go/maximum-value-of-an-ordered-triplet-i.go
Normal file
14
go/maximum-value-of-an-ordered-triplet-i.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
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