780. reaching points

因为x>0,y>0
最显著的特征就是下一个节点(x,y):
y>x or x>y
对于y>x的,一定是来自(x0,x0+y0)
对于x>y的,一定是来自(x0+y0,x0)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public boolean reachingPoints(int sx, int sy, int tx, int ty) {
while(tx > sx && ty > sy){
if(ty < tx) tx %= ty;
else ty %= tx;
}

if(sx == tx&& ty - sy>=0){
return (ty - sy) % sx == 0;
}else if(sy == ty && tx - sx>=0){
return (tx - sx) % sy == 0;
}
return false;
}

}