g0701_0800.s0780_reaching_points.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java11 Show documentation
Show all versions of leetcode-in-java11 Show documentation
Java Solution for LeetCode algorithm problems, continually updating
The newest version!
package g0701_0800.s0780_reaching_points;
// #Hard #Math #2022_03_26_Time_0_ms_(100.00%)_Space_41.3_MB_(32.70%)
public class Solution {
public boolean reachingPoints(int sx, int sy, int tx, int ty) {
while (tx >= sx && ty >= sy) {
if (tx > ty) {
if (ty == sy) {
// ty==sy
return (tx - sx) % sy == 0;
} else {
// ty > sy
tx %= ty;
}
} else if (sx == tx) {
// ty >= tx
return (ty - sy) % sx == 0;
} else {
// (tx > sx)
ty %= tx;
}
}
return false;
}
}