blob: e708e0ccaefbaaea00bf324da395f4c0fd18d815 (
plain) (
blame)
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
|
#!/usr/bin/env python
class Solution:
def isPathCrossing(self, path: str) -> bool:
x = 0
y = 0
visited = set()
visited.add((x, y))
for i in path:
if i == "N":
y += 1
elif i == "S":
y -= 1
elif i == "E":
x += 1
else:
x -= 1
if (x, y) in visited:
return True
visited.add((x, y))
return False
def main():
solution = Solution()
print(solution.isPathCrossing("NES"))
if __name__ == "__main__":
main()
|