780 Reaching Points
780. Reaching Points
1. Question
A move consists of taking a point(x, y)
and transforming it to either(x, x+y)
or(x+y, y)
.
Given a starting point(sx, sy)
and a target point(tx, ty)
, returnTrue
if and only if a sequence of moves exists to transform the point(sx, sy)
to(tx, ty)
. Otherwise, returnFalse
.
Note:
sx, sy, tx, ty
will all be integers in the range[1, 10^9]
.
2. Implementation
(1) BFS (TLE)
(2) Math
思路:看解析
3. Time & Space Complexity
Math: 时间复杂度O(max(tx, ty)), 空间复杂度O(1)
Last updated