Class Solution

java.lang.Object
g0301_0400.s0335_self_crossing.Solution

public class Solution extends Object
335 - Self Crossing.<p>Hard</p> <p>You are given an array of integers <code>distance</code>.</p> <p>You start at point <code>(0,0)</code> on an <strong>X-Y</strong> plane and you move <code>distance[0]</code> meters to the north, then <code>distance[1]</code> meters to the west, <code>distance[2]</code> meters to the south, <code>distance[3]</code> meters to the east, and so on. In other words, after each move, your direction changes counter-clockwise.</p> <p>Return <code>true</code> if your path crosses itself, and <code>false</code> if it does not.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/03/14/selfcross1-plane.jpg" alt="" /></p> <p><strong>Input:</strong> distance = [2,1,1,2]</p> <p><strong>Output:</strong> true</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/03/14/selfcross2-plane.jpg" alt="" /></p> <p><strong>Input:</strong> distance = [1,2,3,4]</p> <p><strong>Output:</strong> false</p> <p><strong>Example 3:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/03/14/selfcross3-plane.jpg" alt="" /></p> <p><strong>Input:</strong> distance = [1,1,1,1]</p> <p><strong>Output:</strong> true</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= distance.length <= 10<sup>5</sup></code></li> <li><code>1 <= distance[i] <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isSelfCrossing

      public boolean isSelfCrossing(int[] x)