因为x>0,y>0最显著的特征就是下一个节点(x,y):y>x or x>y对于y>x的,一定是来自(x0,x0+y0)对于x>y的,一定是来自(x0+y0,x0) 12345678910111213141516 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; }} 赞微海报分享
近期评论