1
class Solution {
2
public:
3
bool isPathCrossing(string path) {
4
set<pair<int, int>> st;
5

6
int x = 0, y = 0;
7

8
st.insert({0, 0});
9

10
for (int i = 0; i < path.length(); i++) {
11
if (path[i] == 'N') {
12
x++;
13
}
14

15
else if (path[i] == 'S') {
16
x--;
17
}
18

19
else if (path[i] == 'E') {
20
y++;
21
}
22

23
else {
24
y--;
25
}
26

27
// if pair find at any point, return true
28
if (st.find({x, y}) != st.end()) {
29
return 1;
30
}
31
// insert the pair
32
st.insert({x, y});
33
}
34
return 0;
35
}
36
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0