-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathJudgeRouteCircle.cpp
More file actions
35 lines (30 loc) · 812 Bytes
/
Copy pathJudgeRouteCircle.cpp
File metadata and controls
35 lines (30 loc) · 812 Bytes
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
class Solution {
public:
void modifyPair(pair<int, int>& p, int l, int r, int u, int d){
p.first += r-l;
p.second += u-d;
}
bool judgeCircle(string moves) {
pair<int, int> p(0, 0);
int i = 0, n = moves.size();
while(i < n){
if(moves[i] == 'L'){
modifyPair(p, 1, 0, 0, 0);
}
else if(moves[i] == 'R'){
modifyPair(p, 0, 1, 0, 0);
}
else if(moves[i] == 'U'){
modifyPair(p, 0, 0, 1, 0);
}
else{
modifyPair(p, 0, 0, 0, 1);
}
i++;
}
if(p.first == 0 && p.second == 0){
return true;
}
return false;
}
};