File tree Expand file tree Collapse file tree 4 files changed +75
-21
lines changed
solution/0600-0699/0657.Robot Return to Origin Expand file tree Collapse file tree 4 files changed +75
-21
lines changed Original file line number Diff line number Diff line change 3636<!-- 这里可写当前语言的特殊实现逻辑 -->
3737
3838``` python
39-
39+ class Solution :
40+ def judgeCircle (self , moves : str ) -> bool :
41+ x = y = 0
42+ for c in moves:
43+ if c == ' R' :
44+ x += 1
45+ elif c == ' L' :
46+ x -= 1
47+ elif c == ' U' :
48+ y += 1
49+ elif c == ' D' :
50+ y -= 1
51+ return x == 0 and y == 0
4052```
4153
4254### ** Java**
4355
4456<!-- 这里可写当前语言的特殊实现逻辑 -->
4557
4658``` java
47-
59+ class Solution {
60+ public boolean judgeCircle (String moves ) {
61+ int x = 0 , y = 0 ;
62+ for (int i = 0 ; i < moves. length(); ++ i) {
63+ char c = moves. charAt(i);
64+ if (c == ' R' ) ++ x;
65+ else if (c == ' L' ) -- x;
66+ else if (c == ' U' ) ++ y;
67+ else if (c == ' D' ) -- y;
68+ }
69+ return x == 0 && y == 0 ;
70+ }
71+ }
4872```
4973
5074### ** ...**
Original file line number Diff line number Diff line change 4343### ** Python3**
4444
4545``` python
46-
46+ class Solution :
47+ def judgeCircle (self , moves : str ) -> bool :
48+ x = y = 0
49+ for c in moves:
50+ if c == ' R' :
51+ x += 1
52+ elif c == ' L' :
53+ x -= 1
54+ elif c == ' U' :
55+ y += 1
56+ elif c == ' D' :
57+ y -= 1
58+ return x == 0 and y == 0
4759```
4860
4961### ** Java**
5062
5163``` java
52-
64+ class Solution {
65+ public boolean judgeCircle (String moves ) {
66+ int x = 0 , y = 0 ;
67+ for (int i = 0 ; i < moves. length(); ++ i) {
68+ char c = moves. charAt(i);
69+ if (c == ' R' ) ++ x;
70+ else if (c == ' L' ) -- x;
71+ else if (c == ' U' ) ++ y;
72+ else if (c == ' D' ) -- y;
73+ }
74+ return x == 0 && y == 0 ;
75+ }
76+ }
5377```
5478
5579### ** ...**
Original file line number Diff line number Diff line change 1+ class Solution {
2+ public boolean judgeCircle (String moves ) {
3+ int x = 0 , y = 0 ;
4+ for (int i = 0 ; i < moves .length (); ++i ) {
5+ char c = moves .charAt (i );
6+ if (c == 'R' ) ++x ;
7+ else if (c == 'L' ) --x ;
8+ else if (c == 'U' ) ++y ;
9+ else if (c == 'D' ) --y ;
10+ }
11+ return x == 0 && y == 0 ;
12+ }
13+ }
Original file line number Diff line number Diff line change 11class Solution :
2- def judgeCircle (self , moves ):
3- """
4- :type moves: str
5- :rtype: bool
6- """
7-
8- x = 0
9- y = 0
10- for each in moves :
11- if ( each == 'U' ):
12- y += 1
13- elif ( each == 'D' ):
14- y -= 1
15- elif ( each == 'R' ):
2+ def judgeCircle (self , moves : str ) -> bool :
3+ x = y = 0
4+ for c in moves :
5+ if c == 'R' :
166 x += 1
17- elif ( each == 'L' ) :
7+ elif c == 'L' :
188 x -= 1
19-
20- return x == y == 0
9+ elif c == 'U' :
10+ y += 1
11+ elif c == 'D' :
12+ y -= 1
13+ return x == 0 and y == 0
You can’t perform that action at this time.
0 commit comments