mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 20:40:39 +08:00
657.机器人能否返回原点 添加go版本
This commit is contained in:
@ -112,6 +112,25 @@ class Solution:
|
|||||||
## Go
|
## Go
|
||||||
|
|
||||||
```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
|
## JavaScript
|
||||||
|
Reference in New Issue
Block a user