I am trying to get a highest number count using GO CODE below but i seems to be not working. which is a simple program but i was unable to get the correct answer which is 2 in this case.
package main
import (
"fmt"
)
func main() {
fmt.Print(findLargeNumberCount([]int32{4, 4, 1, 3}))
}
func findLargeNumberCount(candles []int32) int32 {
var highest int32 = 0
var prev int32 = candles[0]
for i := 1; i < len(candles); i {
if prev == candles[i] {
highest
} else if candles[i] > prev {
highest = 1
}
prev = candles[i]
}
return highest
}
CodePudding user response:
You should change your code to have it works:
package main
import (
"fmt"
)
func main() {
fmt.Print(findLargeNumberCount([]int32{4, 4, 1, 3}))
}
func findLargeNumberCount(candles []int32) int32 {
var highest int32 = 1
var prev int32 = candles[0]
for i := 1; i < len(candles); i {
if prev == candles[i] {
highest
} else if candles[i] > prev {
prev = candles[i]
highest = 1
}
}
return highest
}