#972
Equal Rational Numbers
candidate master · 1585 · lc hard +32 · verified · 46% accepted · 106 likes · top 30%
Description
Strings s and t each encode a non-negative rational number; digits in parentheses repeat infinitely (e.g., "0.1(6)" = 0.1666...). Return true if s and t represent the same number, false otherwise.
Example 1:
Input: s = "0.(52)", t = "0.5(25)"
Output: true
Explanation: Because "0.(52)" represents 0.52525252..., and "0.5(25)" represents 0.52525252525..... , the strings represent the same number.
Example 2:
Input: s = "0.1666(6)", t = "0.166(66)"
Output: true
Example 3:
Input: s = "0.9(9)", t = "1."
Output: true
Explanation: "0.9(9)" represents 0.999999999... repeated forever, which equals 1. [See this link for an explanation.]
"1." represents the number 1, which is formed correctly: (IntegerPart) = "1" and (NonRepeatingPart) = "".
Code
1
2
3