-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1496.cpp
More file actions
29 lines (29 loc) · 711 Bytes
/
1496.cpp
File metadata and controls
29 lines (29 loc) · 711 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
class Solution {
public:
bool isPathCrossing(string path) {
unordered_set<int> st;
int x = 0;
int y = 0;
st.insert((x << 15) + y);
for (auto& c : path) {
switch (c) {
case 'N':
y += 1;
break;
case 'S':
y -= 1;
break;
case 'E':
x += 1;
break;
case 'W':
x -= 1;
break;
}
int pos = (x << 15) + y;
if (st.count(pos)) return true;
st.insert(pos);
}
return false;
}
};