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 +}; +``` + +