LeetCode_335 路径交叉(Java版)
作者:互联网
只有如下三种情况:
/* i-2
case 1 : i-1┌─┐
└─┼─>i
i-3
i-2
case 2 : i-1 ┌────┐
└─══>┘i-3
i i-4 (i overlapped i-4)
case 3 : i-4
┌──┐
│i<┼─┐
i-3│ i-5│i-1
└────┘
i-2
*/
public class Solution_335 {
public boolean isSelfCrossing(int[] distance) {
for (int i = 3; i < distance.length; i++) {
if (distance[i] >= distance[i-2] && distance[i-1] <= distance[i-3]){
return true;
}
if (i == 4 && distance[1] == distance[3] && distance[0] + distance[4] == distance[2]){
return true;
}
if (i >= 5 && distance[i-1] >= distance[i-3]-distance[i-5] && distance[i-1] <= distance[i-3] &&
distance[i] >= distance[i-2] - distance[i-4] && distance[i-2] >= distance[i-4]){
return true;
}
}
return false;
}
}
标签:case,distance,Java,335,public,int,&&,LeetCode 来源: https://www.cnblogs.com/Tianhaoblog/p/15483865.html