Description
You are given an array of integers distance. You start at the point (0, 0) on an X-Y plane, and you move distance[0] meters to the north, then distance[1] meters to the west, distance[2] meters to the south, distance[3] meters to the east, and so on. Return true if your path crosses itself at any point.
Examples
Input:
distance = [2,1,1,2]Output:
trueExplanation:
The path crosses itself.
Input:
distance = [2, 1, 1, 2]Output:
trueExplanation:
Moving north 2, west 1, south 1, then east 2 causes the fourth segment to cross the first segment, so the path crosses itself.
Input:
distance = [1, 2, 3, 4]Output:
falseExplanation:
Each move is longer than the one two steps before it, so the path spirals outward and never crosses itself.
Constraints
- •
1 ≤ distance.length ≤ 10⁵ - •
1 ≤ distance[i] ≤ 10⁵