#1496
Path Crossing
pupil · 350 · lc easy +23 · verified · 62.6% accepted · 1,552 likes · top 64%
Description
You start at position (0, 0) on a 2D plane and follow string path, where each character 'N', 'S', 'E', or 'W' moves you one unit in that direction. Return true if you ever revisit a previously visited position, or false if the path never crosses itself.
Example 1:
Input: path = "NES"
Output: false
Explanation: Notice that the path doesn't cross any point more than once.
Example 2:
Input: path = "NESWW"
Output: true
Explanation: Notice that the path visits the origin twice.
Code
1
2
3