We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4096ed7 commit 2152c42Copy full SHA for 2152c42
scripts/algorithms/P/Path Crossing/Path Crossing.cpp
@@ -1,31 +1,32 @@
1
+// Runtime: 3 ms (Top 71.20%) | Memory: 6.8 MB (Top 80.05%)
2
class Solution {
3
public:
4
bool isPathCrossing(string path) {
-
5
+
6
set<pair<int, int>>st;
7
8
int x=0,y=0;
9
10
st.insert({0, 0});
11
12
for(int i=0;i<path.length();i++){
13
14
if(path[i]=='N'){
15
x++;
16
}
17
18
else if(path[i]=='S'){
19
x--;
20
21
22
else if(path[i]=='E'){
23
y++;
24
25
26
else{
27
y--;
28
29
30
//if pair find at any point, return true
31
if(st.find({x,y}) != st.end()){
32
return 1;
@@ -35,4 +36,4 @@ class Solution {
35
36
37
return 0;
38
-};
39
+};
0 commit comments