From d791cc76b6779799779c33f77fc4c6e59d7a6fee Mon Sep 17 00:00:00 2001 From: wang2jun <91008685+wang2jun@users.noreply.github.com> Date: Mon, 21 Nov 2022 13:27:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20657.=20=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=BA=BA=E8=83=BD=E5=90=A6=E8=BF=94=E5=9B=9E=E5=8E=9F=E7=82=B9?= =?UTF-8?q?=20TypeScript=20=E7=89=88=E6=9C=AC=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加 657. 机器人能否返回原点 TypeScript 版本代码 --- problems/0657.机器人能否返回原点.md | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/problems/0657.机器人能否返回原点.md b/problems/0657.机器人能否返回原点.md index 017c5ecc..ab4bf152 100644 --- a/problems/0657.机器人能否返回原点.md +++ b/problems/0657.机器人能否返回原点.md @@ -150,6 +150,37 @@ var judgeCircle = function(moves) { ``` +## TypeScript + +```ts +var judgeCircle = function (moves) { + let x = 0 + let y = 0 + for (let i = 0; i < moves.length; i++) { + switch (moves[i]) { + case 'L': { + x-- + break + } + case 'R': { + x++ + break + } + case 'U': { + y-- + break + } + case 'D': { + y++ + break + } + } + } + return x === 0 && y === 0 +}; +``` + +