Class Solution

java.lang.Object
g1401_1500.s1496_path_crossing.Solution

public class Solution extends Object
1496 - Path Crossing.<p>Easy</p> <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path specified by <code>path</code>.</p> <p>Return <code>true</code> <em>if the path crosses itself at any point, that is, if at any time you are on a location you have previously visited</em>. Return <code>false</code> otherwise.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/06/10/screen-shot-2020-06-10-at-123929-pm.png" alt="" /></p> <p><strong>Input:</strong> path = &ldquo;NES&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> Notice that the path doesn&rsquo;t cross any point more than once.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/06/10/screen-shot-2020-06-10-at-123843-pm.png" alt="" /></p> <p><strong>Input:</strong> path = &ldquo;NESWW&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> Notice that the path visits the origin twice.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= path.length <= 10<sup>4</sup></code></li> <li><code>path[i]</code> is either <code>'N'</code>, <code>'S'</code>, <code>'E'</code>, or <code>'W'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isPathCrossing

      public boolean isPathCrossing(String path)