-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path657.cpp
More file actions
21 lines (21 loc) · 736 Bytes
/
Copy path657.cpp
File metadata and controls
21 lines (21 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public:
bool judgeCircle(string moves) {
int n = moves.size();
vector<int> hori, vert;
for (int i = 0; i < n; ++i) {
if (moves[i] == 'L' || moves[i] == 'R') {
hori.push_back(moves[i]);
if (hori.size() > 1 && hori[hori.size() - 1] != hori[hori.size() - 2])
hori.erase(hori.end() - 2, hori.end());
} else {
vert.push_back(moves[i]);
if (vert.size() > 1 && vert[vert.size() - 1] != vert[vert.size() - 2])
vert.erase(vert.end() - 2, vert.end());
}
}
if (!vert.size() && !hori.size())
return true;
return false;
}
};