到达目标点的网格图移动问题 - Java 代码实现
class Solution { public boolean reachingPoints(int sx, int sy, int tx, int ty) { while (tx >= sx && ty >= sy) { if (tx == ty) { break; } if (tx > ty) { if (ty > sy) { tx %= ty; } else { return (tx - sx) % ty == 0; } } else { if (tx > sx) { ty %= tx; } else { return (ty - sy) % tx == 0; } } } return tx == sx && ty == sy; } }
原文地址: https://www.cveoy.top/t/topic/nPSm 著作权归作者所有。请勿转载和采集!