1496. Path Crossing
Easy
Previous1493. Longest Subarray of 1's After Deleting One Element ⭐Next1497. Check If Array Pairs Are Divisible by k
Last updated
Easy
Last updated
Given a string path
, where path[i] = 'N'
, 'S'
, 'E'
or 'W'
, each representing moving one unit north, south, east, or west, respectively. You start at the origin (0, 0)
on a 2D plane and walk on the path specified by path
.
Return true
if the path crosses itself at any point, that is, if at any time you are on a location you have previously visited. Return false
otherwise.
Example 1:
Example 2:
Constraints:
1 <= path.length <= 104
path[i]
is either 'N'
, 'S'
, 'E'
, or 'W'
.
Runtime: 0 ms, faster than 100.00%
Memory Usage: 2.2 MB, less than 26.09%