刚开始用了个 map
,比较复杂,后来看了答案,按照这种简单的方式,并且做了 len(moves) % 2 != 0
的判断
func judgeCircle(moves string) bool {
x, y := 0, 0
if len(moves) % 2 != 0 {
return false
}
for _, v := range moves {
vv := string(v)
if vv == "R" {
x++
} else if vv == "L" {
x--
} else if vv == "U" {
y++
} else if vv == "D" {
y--
}
}
return x == 0 && y == 0
}
标签:原点,机器人,else,657,vv,moves,leetcode
From: https://www.cnblogs.com/wudanyang/p/17028642.html