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;
}