780. Reaching Points
idea:
1.从后向前找
2.while (tx > ty) tx -= ty; 替为 % 操作
3.经过循环后,必定只有两种情况才true
- sx == tx && sy <= ty && (ty - sy) % sx == 0
- sy == ty && sx <= tx && (tx - sx) % sy == 0
public boolean reachingPoints(int sx, int sy, int tx, int ty) {
while (tx > sx && ty > sy){
if (tx > ty) tx %= ty;
else ty %= tx;
}
return sx == tx && sy <= ty && (ty - sy) % sx == 0 ||
sy == ty && sx <= tx && (tx - sx) % sy == 0;
}
780. Reaching Points的更多相关文章
- [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 ...
- LeetCode 780. Reaching Points
题目链接:https://leetcode.com/problems/reaching-points/ 题意:给定操作可以使点(x,y)变为点(x+y,y)或者点(x,x+y).现已知初始点(sx,s ...
- [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 ...
- [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 ...
- 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 ...
- 【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 ...
- LeetCode All in One题解汇总(持续更新中...)
突然很想刷刷题,LeetCode是一个不错的选择,忽略了输入输出,更好的突出了算法,省去了不少时间. dalao们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对 ...
- leetcode 学习心得 (4)
645. Set Mismatch The set S originally contains numbers from 1 to n. But unfortunately, due to the d ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
随机推荐
- SSM-动态SQL
SSM-动态SQL ssm框架 Mybatis 动态SQL主要是解决同一类SQL语句匹配不同的问题,举个栗子: 加入我要执行一个查询语句,但是是一个不确定的查询语句,可能会根据ID去查,如果ID没有 ...
- Umbraco 7 特点
Umbraco 7 features at a glance The backend is mainly built on .NET C# MVC. There are some leftovers ...
- override与new的区别
using System; namespace ConsoleAppDemo { class BaseClass { public void Fun() { Console.WriteLine(&qu ...
- 修改mysql忽略大小写
mysql -p --1.登录mysql show variables like "%case%";+------------------------+-------+| Vari ...
- response slider
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- C语言字符串读入函数笔记
gets(str)函数和scanf("%s",str)区别: 转自:https://zhidao.baidu.com/question/290403568.html 二者都是从终端 ...
- sql script: Graphs, Trees, Hierarchies and Recursive Queries
--------------------------------------------------------------------- -- Inside Microsoft SQL Server ...
- TP5手动引入PHPEXCEL的方法
1.先在github里面下载PHPexcel这个类库 2.解压之后把它复制到extend里面 控制器代码如下: 1 <?php 2 /** 3 * Created by PhpStorm. 4 ...
- 洛谷P4424 [HNOI/AHOI2018]寻宝游戏(思维题)
题意 题目链接 Sol 神仙题Orz Orz zbq爆搜70.. 考虑"与"和"或"的性质 \(0 \& 0 = 0, 1 \& 0 = 0\) ...
- 【读书笔记】iOS-自定义URL Scheme注意事项
如果两个不同的应用注册了同样的URL Scheme,那么后安装的应用会响应符合这种协议格式的URL. 如果你的应用的iPhone和iPad版是各自独立的(即不是Universal类型的),那么你就不应 ...