From 3738c49630e2a3447a1d80e465964af5deb7caa1 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Fri, 22 Dec 2023 22:54:00 -0500 Subject: 1496 --- 1496/main.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 1496/main.py diff --git a/1496/main.py b/1496/main.py new file mode 100755 index 0000000..e708e0c --- /dev/null +++ b/1496/main.py @@ -0,0 +1,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() -- cgit v1.2.3