780. Reaching Points
Read the full problem statement on LeetCode.
Difficulty: hard Acceptance: 34% Topics: Math
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(log(max(m, n)))
# Space: O(1)
class Solution(object):
def reachingPoints(self, sx, sy, tx, ty):
"""
:type sx: int
:type sy: int
:type tx: int
:type ty: int
:rtype: bool
"""
while tx >= sx and ty >= sy:
if tx < ty:
sx, sy = sy, sx
tx, ty = ty, tx
if ty > sy:
tx %= ty
else:
return (tx - sx) % ty == 0
return False
Solution from kamyu104/LeetCode-Solutions · MIT