You are viewing a single comment's thread. Return to all comments →
go
func sum(slice []int32) int32 { total := int32(0) for _, n := range slice { total += n } return total } func getHeights(slice []int32) []int32 { heights := make([]int32, len(slice)) sum := sum(slice) for i, n := range slice { heights[i] = sum sum -= n } return heights } func equalStacks(h1 []int32, h2 []int32, h3 []int32) int32 { var stack []int32 stack = append(stack, getHeights(h1)...) stack = append(stack, getHeights(h2)...) stack = append(stack, getHeights(h3)...) sort.Slice(stack, func(i, j int) bool { return stack[i] > stack[j] }) for i := 0; i < len(stack)-2; i++ { if stack[i] == stack[i+1] && stack[i] == stack[i+2] { return stack[i] } } return 0 }
Seems like cookies are disabled on this browser, please enable them to open this website
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
go