我已经开始学习 Go,但我遇到了一个奇怪的错误,还有一个更奇怪的修复程序,用于解决HackerRack 问题:
func countingValleys(steps int32, path string) int32 {
// Write your code here
var level int32 = 0
var valleys int32 = 0
// The below declaration was throwing the initial error
insideValley := false
for _, char := range path {
fmt.Println(insideValley)
if string(char) == "U" {
if level == -1 {
insideValley = false
valleys += 1
}
level += 1
} else if string(char) == "D"{
if level == 0 {
insideValley = …Run Code Online (Sandbox Code Playgroud) go ×1