Skip to content

Commit

Permalink
增加 657. 机器人能否返回原点 TypeScript 版本代码
Browse files Browse the repository at this point in the history
增加 657. 机器人能否返回原点 TypeScript 版本代码
  • Loading branch information
wang2jun authored Nov 21, 2022
1 parent b7d29cb commit d791cc7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions problems/0657.机器人能否返回原点.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
```


<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
Expand Down

0 comments on commit d791cc7

Please sign in to comment.