-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1496.cpp
More file actions
37 lines (33 loc) · 867 Bytes
/
1496.cpp
File metadata and controls
37 lines (33 loc) · 867 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
36
37
class Solution {
public:
bool isPathCrossing(string path) {
set<pair<int, int>> s;
int x = 0;
int y = 0;
s.insert(pair<int, int>(0,0));
for(int i = 0; i < path.length(); i++){
switch(path[i]){
case 'N':
y++;
break;
case 'S':
y--;
break;
case 'E':
x++;
break;
case 'W':
x--;
break;
default:
break;
}
if(s.count(pair<int, int>(x,y))){
return true;
}else{
s.insert(pair<int, int>(x,y));
}
}
return false;
}
};