Skip to content

Commit fb6d16d

Browse files
Question 1496 has been solved.
1 parent 1460dd0 commit fb6d16d

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Q1496 - Path Crossing/1496.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution {
2+
public:
3+
bool isPathCrossing(string path) {
4+
5+
int x = 0, y = 0;
6+
set<pair<int, int>> points;
7+
points.insert({ x,y });
8+
9+
for (int i = 0; i < path.length(); i++) {
10+
if (path[i] == 'N')
11+
{
12+
y++;
13+
}
14+
if (path[i] == 'S')
15+
{
16+
y--;
17+
}
18+
if (path[i] == 'E')
19+
{
20+
x++;
21+
}
22+
if (path[i] == 'W')
23+
{
24+
x--;
25+
}
26+
auto temp = points.insert({ x,y });
27+
if (temp.second == false)
28+
return true;
29+
}
30+
return false;
31+
}
32+
};

Q1496 - Path Crossing/1496.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution:
2+
def isPathCrossing(self, path: str) -> bool:
3+
x=0
4+
y=0
5+
points= set()
6+
7+
str="{}, {}".format(x,y)
8+
points.add(str)
9+
for i in range(len(path)):
10+
if(path[i]=='N'):
11+
y=y+1
12+
13+
if(path[i]=='S'):
14+
y=y-1
15+
16+
if(path[i]=='E'):
17+
x=x+1
18+
19+
if(path[i]=='W'):
20+
x=x-1
21+
22+
l = len(points)
23+
str="{}, {}".format(x,y)
24+
points.add(str)
25+
26+
if (len(points) == l):
27+
return True
28+
29+
return False

0 commit comments

Comments
 (0)