-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
657.cpp
60 lines (57 loc) · 1.39 KB
/
657.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
__________________________________________________________________________________________________
sample 8 ms submission
int any = []() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
return 0;
}();
class Solution {
public:
bool judgeCircle(string moves) {
int count[2] = { 0 };
for (char l : moves)
switch (l) {
case 'U':
++count[0];
break;
case 'D':
--count[0];
break;
case 'L':
++count[1];
break;
case 'R':
--count[1];
break;
}
return count[0] == 0 && count[1] == 0;
}
};
__________________________________________________________________________________________________
sample 9988 kb submission
class Solution {
public:
bool judgeCircle(string& moves) {
int movementHeight = 0;
int movementWeight = 0;
for (int i = 0; i < moves.length(); i++ ) {
if(moves[i] == 'U') {
movementHeight ++;
}
else if(moves[i] == 'D') {
movementHeight --;
}
else if(moves[i] == 'L') {
movementWeight --;
}
else {
movementWeight ++;
}
}
if(movementWeight == 0 && movementHeight == 0){
return true;
}
else return false;
}
};
__________________________________________________________________________________________________