1
from collections import defaultdict
2

3

4
class Solution:
5
def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:
6
def nextNum(ta, tb, s):
7
if ta % tb == s % tb:
8
return min(ta, s)
9
return ta % tb
10

11
visited = defaultdict(bool)
12
while tx >= sx and ty >= sy and (sx != tx or sy != ty):
13
if tx > ty:
14
tx, ty = nextNum(tx, ty, sx), ty
15
else:
16
tx, ty = tx, nextNum(ty, tx, sy)
17
if visited[(tx, ty)]:
18
break
19
visited[(tx, ty)] = True
20
return (sx == tx) and (sy == ty)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0