A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y).

Given a starting point (sx, sy) and a target point (tx, ty), return True if and only if a sequence of moves exists to transform the point (sx, sy) to (tx, ty). Otherwise, return False.

Examples:
Input: sx = 1, sy = 1, tx = 3, ty = 5
Output: True
Explanation:
One series of moves that transforms the starting point to the target is:
(1, 1) -> (1, 2)
(1, 2) -> (3, 2)
(3, 2) -> (3, 5) Input: sx = 1, sy = 1, tx = 2, ty = 2
Output: False Input: sx = 1, sy = 1, tx = 1, ty = 1
Output: True 分析:因为对于起始点来讲,它后面的x和y值永远是增加的,所以,如果sx > tx 或者 sy > ty,那么明显是不行的。
但是从小到大找好像不好找,可以换种思维,从大往小找。
 class Solution {
public boolean reachingPoints(int sx, int sy, int tx, int ty) {
if (ty < sy || tx < sx) return false;
while (tx >= sx && ty >= sy) {
if (tx > ty) tx %= ty;
else ty %= tx;
}
if (tx == sx) {
return (ty - sy) % sx == ;
}
if (ty == sy) {
return (tx - sx) % sy == ;
}
return false;
}
}

Reaching Points的更多相关文章

  1. [Swift]LeetCode780. 到达终点 | Reaching Points

    A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y). Given a ...

  2. [LeetCode] Reaching Points 到达指定点

    A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y). Given a ...

  3. 780. Reaching Points

    idea: 1.从后向前找 2.while (tx > ty) tx -= ty; 替为 % 操作 3.经过循环后,必定只有两种情况才true sx == tx && sy &l ...

  4. [LeetCode] 780. Reaching Points 到达指定点

    A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y). Given a ...

  5. 【leetcode】Reaching Points

    题目如下: A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y). G ...

  6. LeetCode 780. Reaching Points

    题目链接:https://leetcode.com/problems/reaching-points/ 题意:给定操作可以使点(x,y)变为点(x+y,y)或者点(x,x+y).现已知初始点(sx,s ...

  7. [LeetCode] Gas Station 加油站问题

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  8. Swift LeetCode 目录 | Catalog

    请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如 ...

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

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

随机推荐

  1. ila核数据输出

    在Tcl Console中输入以下命令(其中dataxxxx表示文件名,hw_ila_2则为ila窗口名): write_hw_ila_data -csv_file -force dataxxxx [ ...

  2. @ComponentScan什么时候可以不加

    SpringBoot在没配置@ComponentScan的情况下,默认只扫描和主类处于同包下的Class. 主类Application.java: import org.springframework ...

  3. deepin Linux 日常命令、插件、方法等汇总【更新中】

    查看系统编码: dawn@dawn-PC:~$ locale LANG=zh_CN.UTF- LANGUAGE=zh_CN LC_CTYPE="zh_CN.UTF-8" LC_NU ...

  4. html页面之间相互传值

    常见的在页面登录过后会获得一个token值然后页面跳转时传给下一个页面 sessionStorage.setItem("token",result.token);//传输token ...

  5. Codeforces 1051 D.Bicolorings(DP)

    Codeforces 1051 D.Bicolorings 题意:一个2×n的方格纸,用黑白给格子涂色,要求分出k个连通块,求方案数. 思路:用0,1表示黑白,则第i列可以涂00,01,10,11,( ...

  6. Ranorex连接Android

    开始在Android上进行移动测试 只需按照下面的步骤开始使用Android进行移动测试. 1.连接设备(USB/Wi-Fi) 2.在Ranorex中添加设备 3.将设备名称设置为参数值 4.运行示例 ...

  7. 【转】mysql基础汇总

    mysql基础知识语法汇总整理(二)  原文:https://www.cnblogs.com/cxx8181602/p/9525950.html 连接数据库操作 /*连接mysql*/ mysql - ...

  8. 整个系统禁用复制功能下,js实现部分数据的复制功能

    需求背景:整个系统禁止复制,列表页操作栏新增按钮来复制数据列的手机号功能 感受下是怎么回事?看下效果 (GIF有点点烂)

  9. openapi and light-4j

    light-4j项目支持openapi规范,本文介绍一下参照相关demo做的上传功能. openapi.yaml,按照规范编写内容,/openapi/swagger可以查看对应的swagger页面,A ...

  10. R语言:载入rjava(xlsx)包报错

    先安装JRE,在电脑中添加环境变量: 电脑-右键-属性-高级系统设置-环境变量-用户变量下新建:变量名:JAVA-HOME,变量值:JRE安装路径(到jre1.8***这个文件夹就行了) 系统变量下找 ...