Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 884 Bytes

335.self-crossing.md

File metadata and controls

30 lines (24 loc) · 884 Bytes

这是一道脑筋急转弯的题目

明确题意,我们的移动方向只能是逆时针移动

我们分析相交的几种情况

2021-10-29 am10.23.42

代码实现

class Solution {
    public boolean isSelfCrossing(int[] d) {
        int n = d.length;
        if (n<=3) return false;
        for (int i = 3; i <n; i++) {
            if (d[i] >= d[i-2] && d[i-3] >= d[i-1]) return true;
        }
        for (int i = 4; i<n; i++ ) {
            if (d[i] + d[i-4] >= d[i-2] && d[i-3] == d[i-1]) return true;
        }
        for (int i = 5; i<n; i++) {
            if (d[i-2] > d[i-4] && d[i] + d[i-4] >= d[i-2] && d[i-3] > d[i-1] && d[i-1] + d[i-5] >= d[i-3]) return true;
        }
        return false;
    }
}