4
def isRationalEqual(self, s: str, t: str) -> bool:7
# write each numbes as fraction: num / den8
# then compare the two fractions.10
num1, den1 = self.toFraction(s)11
num2, den2 = self.toFraction(t)13
return den1 * num2 == den2 * num115
def toFraction(self, s: str) -> typing.Tuple[int, int]:19
intp, frac = s.split(".")20
# decimal dot, but no repeating part:21
# xyz.abc = xyzabc / 100023
ifrac = int(frac) if len(frac) > 0 else 024
num = int(intp) * (10 ** len(frac)) + ifrac28
# this is for cases like a.b(c)30
# then, 10^(len(b+c)) * n = abc.(c)31
# and 10^(len(b)) * n = ab.(c)32
# subtract the two, and solve for n:33
# n = (abc - ab) / (10^len(b + c) - 10^len(b))34
frac, repfrac = frac.split("(")35
repfrac = repfrac[:-1]38
ifrac = int(frac) if len(frac) > 0 else 042
(iintp * (10 ** (len(frac + repfrac))) + ifrac * 10 ** len(repfrac) + irep)43
- (iintp * 10 ** len(frac) + ifrac),44
(10 ** len(frac + repfrac) - 10 ** len(frac)),