/*
* 335. Self Crossing
* 2016-7-10 by Mingyang
*/
// Categorize the self-crossing scenarios, there are 3 of them:
// 1. Fourth line crosses first line and works for fifth line crosses second line and so on...
// 2. Fifth line meets first line and works for the lines after
// 3. Sixth line crosses first line and works for the lines after
public boolean isSelfCrossing(int[] x) {
int l = x.length;
if(l <= 3) return false; for(int i = 3; i < l; 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;
}

335. Self Crossing的更多相关文章

  1. 还记得高中的向量吗?leetcode 335. Self Crossing(判断线段相交)

    传统解法 题目来自 leetcode 335. Self Crossing. 题意非常简单,有一个点,一开始位于 (0, 0) 位置,然后有规律地往上,左,下,右方向移动一定的距离,判断是否会相交(s ...

  2. 【LeetCode】335. Self Crossing(python)

    Problem:You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metr ...

  3. [leetcode]335. Self Crossing

    You are given an array x of n positive numbers. You start at point (,) and moves x[] metres to the n ...

  4. LeetCode All in One 题目讲解汇总(持续更新中...)

    终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...

  5. LeetCode All in One题解汇总(持续更新中...)

    突然很想刷刷题,LeetCode是一个不错的选择,忽略了输入输出,更好的突出了算法,省去了不少时间. dalao们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对 ...

  6. LeetCode分类-前400题

    1. Array 基础 27 Remove Element 26 Remove Duplicates from Sorted Array 80 Remove Duplicates from Sorte ...

  7. Hard模式题目

    先过一下Hard模式的题目吧.   # Title Editorial Acceptance Difficulty Frequency   . 65 Valid Number     12.6% Ha ...

  8. 继续过Hard题目

    接上一篇:http://www.cnblogs.com/charlesblc/p/6283064.html 继续过Hard模式的题目吧.   # Title Editorial Acceptance ...

  9. 继续过Hard题目.0209

    http://www.cnblogs.com/charlesblc/p/6372971.html 继续过Hard模式的题目吧.   # Title Editorial Acceptance Diffi ...

随机推荐

  1. Ubuntu 档案权限

    Linux文件属性:查看指令是:ls -al ls是list的意思,重点在显示档案的文件名与相关属性.而选项-al则表示列出所有的档案详细的权限与属性.

  2. MongoDB学习-->Gridfs分布式存储&DBRef关联查询

    mongodb自带的一个分布式文件系统 fs.files _id filename md5 size uploaddate contenttype metadata {"user_id&qu ...

  3. adb -a server nodaemon,设备一直显示 offline,而 adb devices 一直显示 device【已解决】

    1. adb -a server nodaemon 一直显示 offline 2. adb devices 一直显示 device 谷歌 和 度娘了一圈,未寻得解决办法 # 解决方法 问题已解决,使用 ...

  4. hexo博客发布注意事项

    最近把hexo博客内容写完了,就发布到github上面去,结果就出现各种一些小问题. 1.发布之后,hexo博客的css与js无法访问. 原因:没有配置正确的url路径.(配置文件_config.ym ...

  5. webdriver高级应用- 操作日期控件

    1. 通过点击的方式操作日期控件 #encoding=utf-8 from selenium import webdriver import unittest, time, traceback fro ...

  6. [办公软件][2]screenToGif

    https://github.com/NickeManarin/ScreenToGif/wiki/help 下载: .Net Framework 4.6.1   https://www.microso ...

  7. 【Luogu】P3159交换棋子(超出我能力范围的费用流)

    题目链接 明显超出我能力范围. 只放题解. 再放代码. #include<cstring> #include<algorithm> #include<cstdio> ...

  8. background-position-x和background-position-y的兼容性问题

    一.语法: background-position-x : length | left | center | right background-position-y : length | left | ...

  9. 如何在 Windows 上 使用 ONLYOFFICE 协作编辑文档

    ONLYOFFICE Document Server提供文档协作的服务功能,支持Word,Excel和PowerPoint的协作.但是这里告诉我们,需要进行文档管理和存储的二次开发. Please n ...

  10. BZOJ4259 残缺的字符串 【fft】

    题目 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度为m,B串长度为n.可当你现在再次碰到这两个串时,这两个串已经老化了,每个串都有不同程度的残缺. 你想 ...