1 Star 1 Fork 1

Clock966 / LeetcodeEveryday

forked from 四方云和 / LeetcodeEveryday 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
SelfCrossing.java 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
RunAtWorld 提交于 2020-03-31 00:18 . Java 语言解答 package
package solution;
/**
* 这题非常数学,最好画一下,总的来说可以归纳为三种情况:
* 1. 第4条线和第1条线相交
* 2. 第5条线和第1条线相交
* 3. 第6条线和第1条线相交
*/
public class SelfCrossing {
public boolean isSelfCrossing(int[] x) {
for (int i = 3; i < x.length; i++) {
if (x[i] >= x[i - 2] && x[i - 1] <= x[i - 3]) {
return true; //Fourth line crosses first line and onward
}
if (i >= 4) {
if (x[i - 1] == x[i - 3] && x[i] + x[i - 4] >= x[i - 2]) {
return true; // Fifth line meets first line and onward
}
}
if (i >= 5) {
if (x[i - 2] - x[i - 4] >= 0 && x[i] >= x[i - 2] - x[i - 4]
&& x[i - 1] >= x[i - 3] - x[i - 5] && x[i - 1] <= x[i - 3]) {
return true; // Sixth line crosses first line and onward
}
}
}
return false;
}
}
1
https://gitee.com/Clock966/LeetcodeEveryday.git
git@gitee.com:Clock966/LeetcodeEveryday.git
Clock966
LeetcodeEveryday
LeetcodeEveryday
master

搜索帮助