1619. Path Crossing
My accepted Python solution to LeetCode problem 1619, Path Crossing, running in 3ms.
- Difficulty: Easy
- Python
- Runtime 3ms
- Memory 17.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 3ms, memory 17.2MB, accepted 2025-12-29.
class Solution:
def isPathCrossing(self, path: str) -> bool:
x, y = 0, 0
visited = {(0, 0)}
dirs = {'N': (0, 1), 'S': (0, -1), 'E': (1, 0), 'W': (-1, 0)}
for d in path:
dx, dy = dirs[d]
x, y = x + dx, y + dy
if (x, y) in visited:
return True
visited.add((x, y))
return False