#780
Reaching Points
master · 1875 · lc hard +32 · verified · 34.2% accepted · 1,585 likes · top 12%
Description
Starting from point (sx, sy), you may repeatedly apply one of two operations: replace (x, y) with either (x, x + y) or (x + y, y). Given target coordinates (tx, ty), return true if (tx, ty) is reachable from (sx, sy), otherwise false.
Example 1:
Input: sx = 1, sy = 1, tx = 3, ty = 5
Output: true
Explanation:
One series of moves that transforms the starting point to the target is:
(1, 1) -> (1, 2)
(1, 2) -> (3, 2)
(3, 2) -> (3, 5)
Example 2:
Input: sx = 1, sy = 1, tx = 2, ty = 2
Output: false
Example 3:
Input: sx = 1, sy = 1, tx = 1, ty = 1
Output: true
Code
1
2
3