# 路径交叉
给你一个整数数组 distance 。
从 X-Y 平面上的点 (0,0) 开始,先向北移动 distance[0] 米,然后向西移动 distance[1] 米,向南移动 distance[2] 米,向东移动 distance[3] 米,持续移动。也就是说,每次移动后你的方位会发生逆时针变化。
判断你所经过的路径是否相交。如果相交,返回 true ;否则,返回 false 。
示例 1:
输入:distance = [2,1,1,2]
输出:true
示例 2:
输入:distance = [1,2,3,4]
输出:false
示例 3:
输入:distance = [1,1,1,1]
输出:true
提示:
1 <= distance.length <= 105
1 <= distance[i] <= 105
## template
```cpp
#include
using namespace std;
class Solution
{
public:
bool isSelfCrossing(vector &distance)
{
int all_step = distance.size(), current_step = 0;
if (all_step < 4)
return false;
current_step = 2;
while (current_step < all_step && distance[current_step] > distance[current_step - 2])
current_step++;
if (current_step == all_step)
return false;
if (distance[current_step] >= distance[current_step - 2] - (current_step > 3 ? distance[current_step - 4] : 0))
distance[current_step - 1] -= current_step > 2 ? distance[current_step - 3] : 0;
current_step++;
while (current_step < all_step && distance[current_step] < distance[current_step - 2])
current_step++;
return current_step != all_step;
}
};
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```