1
class Solution {
2
public:
3
bool judgeCircle(string moves) {
4
int n = moves.size();
5
int a = 0;
6
int b = 0;
7
int c = 0;
8
int d = 0;
9
for (int i = 0; i < n; i++) {
10
if (moves[i] == 'R') {
11
a = a + 1;
12
}
13
if (moves[i] == 'L') {
14
b = b + 1;
15
}
16
if (moves[i] == 'U') {
17
c = c + 1;
18
}
19
if (moves[i] == 'D') {
20
d = d + 1;
21
}
22
}
23
/*if(a==b && c==0 && d==0)
24
{
25
return true;
26
}
27
if(c==d && a==0 && b==0)
28
{
29
return true;
30
}*/
31
if (a == b && b == c && c == d) {
32
return true;
33
}
34
if (a == b && c == d) {
35
return true;
36
}
37
return false;
38
}
39
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0