Skip to content

Commit 2152c42

Browse files
committed
Runtime: 3 ms (Top 71.20%) | Memory: 6.8 MB (Top 80.05%)
1 parent 4096ed7 commit 2152c42

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1+
// Runtime: 3 ms (Top 71.20%) | Memory: 6.8 MB (Top 80.05%)
12
class Solution {
23
public:
34
bool isPathCrossing(string path) {
4-
5+
56
set<pair<int, int>>st;
6-
7+
78
int x=0,y=0;
8-
9+
910
st.insert({0, 0});
10-
11+
1112
for(int i=0;i<path.length();i++){
12-
13+
1314
if(path[i]=='N'){
1415
x++;
1516
}
16-
17+
1718
else if(path[i]=='S'){
1819
x--;
1920
}
20-
21+
2122
else if(path[i]=='E'){
2223
y++;
2324
}
24-
25+
2526
else{
2627
y--;
2728
}
28-
29+
2930
//if pair find at any point, return true
3031
if(st.find({x,y}) != st.end()){
3132
return 1;
@@ -35,4 +36,4 @@ class Solution {
3536
}
3637
return 0;
3738
}
38-
};
39+
};

0 commit comments

Comments
 (0)