Go Triangle
func triangle(a []int) int {
sorted := append([]int(nil), a...)
sort.Ints(sorted)
c := len(sorted)
if c < 3 {
return 0
}
for i := 0; i < c-2; i++ {
if sorted[i] > 0 && sorted[i] > sorted[i+2]-sorted[i+1] {
return 1
}
}
return 0
}
This sorts the values and checks nearby triples, because a valid triangle only needs one local match after sorting.