Class Solution

java.lang.Object
g0901_1000.s0972_equal_rational_numbers.Solution

public class Solution extends Object
972 - Equal Rational Numbers.<p>Hard</p> <p>Given two strings <code>s</code> and <code>t</code>, each of which represents a non-negative rational number, return <code>true</code> if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.</p> <p>A <strong>rational number</strong> can be represented using up to three parts: <code><IntegerPart></code>, <code><NonRepeatingPart></code>, and a <code><RepeatingPart></code>. The number will be represented in one of the following three ways:</p> <ul> <li><code><IntegerPart></code> <ul> <li>For example, <code>12</code>, <code>0</code>, and <code>123</code>.</li> </ul> </li> <li><code><IntegerPart>**<.>**<NonRepeatingPart></code> <ul> <li>For example, <code>0.5</code>, <code>1.</code>, <code>2.12</code>, and <code>123.0001</code>.</li> </ul> </li> <li><code><IntegerPart>**<.>**<NonRepeatingPart>**<(>**<RepeatingPart>**<)>**</code> <ul> <li>For example, <code>0.1(6)</code>, <code>1.(9)</code>, <code>123.00(1212)</code>.</li> </ul> </li> </ul> <p>The repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets. For example:</p> <ul> <li><code>1/6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66)</code>.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;0.(52)&rdquo;, t = &ldquo;0.5(25)&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> Because &ldquo;0.(52)&rdquo; represents 0.52525252&hellip;, and &ldquo;0.5(25)&rdquo; represents 0.52525252525&hellip;.. , the strings represent the same number.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;0.1666(6)&rdquo;, t = &ldquo;0.166(66)&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;0.9(9)&rdquo;, t = &ldquo;1.&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> &ldquo;0.9(9)&rdquo; represents 0.999999999&hellip; repeated forever, which equals</p> <ol> <li>[<a href="https://en.wikipedia.org/wiki/0.999..." target="_top">See this link for an explanation.</a>] &ldquo;1.&rdquo; represents the number 1, which is formed correctly: (IntegerPart) = &ldquo;1&rdquo; and (NonRepeatingPart) = &quot;&quot;.</li> </ol> <p><strong>Constraints:</strong></p> <ul> <li>Each part consists only of digits.</li> <li>The <code><IntegerPart></code> does not have leading zeros (except for the zero itself).</li> <li><code>1 <= <IntegerPart>.length <= 4</code></li> <li><code>0 <= <NonRepeatingPart>.length <= 4</code></li> <li><code>1 <= <RepeatingPart>.length <= 4</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isRationalEqual

      public boolean isRationalEqual(String s, String t)