657.机器人能否返回原点 添加go版本

This commit is contained in:
posper
2021-07-31 10:36:59 +08:00
parent 0e832d5183
commit 4851af73ab

View File

@ -112,6 +112,25 @@ class Solution:
## Go
```go
func judgeCircle(moves string) bool {
x := 0
y := 0
for i := 0; i < len(moves); i++ {
if moves[i] == 'U' {
y++
}
if moves[i] == 'D' {
y--
}
if moves[i] == 'L' {
x++
}
if moves[i] == 'R' {
x--
}
}
return x == 0 && y == 0;
}
```
## JavaScript