File tree 4 files changed +75
-21
lines changed
solution/0600-0699/0657.Robot Return to Origin
4 files changed +75
-21
lines changed Original file line number Diff line number Diff line change 36
36
<!-- 这里可写当前语言的特殊实现逻辑 -->
37
37
38
38
``` 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
40
52
```
41
53
42
54
### ** Java**
43
55
44
56
<!-- 这里可写当前语言的特殊实现逻辑 -->
45
57
46
58
``` 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
+ }
48
72
```
49
73
50
74
### ** ...**
Original file line number Diff line number Diff line change 43
43
### ** Python3**
44
44
45
45
``` 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
47
59
```
48
60
49
61
### ** Java**
50
62
51
63
``` 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
+ }
53
77
```
54
78
55
79
### ** ...**
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 1
1
class 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' :
16
6
x += 1
17
- elif ( each == 'L' ) :
7
+ elif c == 'L' :
18
8
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