Skip to content

Commit d6d89f7

Browse files
authored
Create 780-reaching-points.js
1 parent dca54f1 commit d6d89f7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

780-reaching-points.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {number} sx
3+
* @param {number} sy
4+
* @param {number} tx
5+
* @param {number} ty
6+
* @return {boolean}
7+
*/
8+
const reachingPoints = function(sx, sy, tx, ty) {
9+
while (tx >= sx && ty >= sy) {
10+
if (tx === ty) break;
11+
if (tx > ty) {
12+
if (ty > sy) tx %= ty;
13+
else return (tx - sx) % ty === 0;
14+
} else {
15+
if (tx > sx) ty %= tx;
16+
else return (ty - sy) % tx === 0;
17+
}
18+
}
19+
return tx === sx && ty === sy;
20+
};
21+

0 commit comments

Comments
 (0)