You are viewing a single comment's thread. Return to all comments →
Go version of your soln
type Triangle struct { sides []int32 } func (t *Triangle) Isvalid() (bool) { return t.sides[0]+t.sides[1] > t.sides[2] } // Complete the maximumPerimeterTriangle function below. func maximumPerimeterTriangle(sticks []int32) []int32 { sort.Slice(sticks, func(i, j int) (bool) { return sticks[i] < sticks[j] }) n := len(sticks) var t *Triangle for i := n - 3; i >= 0; i-- { t = &Triangle{ sides: sticks[i:i+3], } if t.Isvalid() { return t.sides } } return []int32{-1} }
type Triangle struct { sides []int32 }
func (t *Triangle) Isvalid() (bool) { return t.sides[0]+t.sides[1] > t.sides[2] }
// Complete the maximumPerimeterTriangle function below. func maximumPerimeterTriangle(sticks []int32) []int32 { sort.Slice(sticks, func(i, j int) (bool) { return sticks[i] < sticks[j] }) n := len(sticks)
var t *Triangle
for i := n - 3; i >= 0; i-- { t = &Triangle{ sides: sticks[i:i+3], } if t.Isvalid() { return t.sides } } return []int32{-1} }
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Perimeter Triangle
You are viewing a single comment's thread. Return to all comments →
Go version of your soln