From 4851af73ab4ed58b71c1c6d1223c39d2483816ee Mon Sep 17 00:00:00 2001 From: posper Date: Sat, 31 Jul 2021 10:36:59 +0800 Subject: [PATCH] =?UTF-8?q?657.=E6=9C=BA=E5=99=A8=E4=BA=BA=E8=83=BD?= =?UTF-8?q?=E5=90=A6=E8=BF=94=E5=9B=9E=E5=8E=9F=E7=82=B9=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0go=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0657.机器人能否返回原点.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/problems/0657.机器人能否返回原点.md b/problems/0657.机器人能否返回原点.md index 805a81e6..9b43ea6c 100644 --- a/problems/0657.机器人能否返回原点.md +++ b/problems/0657.机器人能否返回原点.md @@ -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