|
| 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> |
| 2 | +<!--+----------------------------------------------------------------------+--> |
| 3 | +<!--|@author Openset <[email protected]> |--> |
| 4 | +<!--|@link https://github.com/openset |--> |
| 5 | +<!--|@home https://github.com/openset/leetcode |--> |
| 6 | +<!--+----------------------------------------------------------------------+--> |
| 7 | + |
| 8 | +## 972. Equal Rational Numbers (Hard) |
| 9 | + |
| 10 | +<p>Given two strings <code>S</code> and <code>T</code>, each of which represents a non-negative rational number, return <strong>True</strong> if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.</p> |
| 11 | + |
| 12 | +<p>In general a rational number can be represented using up to three parts: an <em>integer part</em>, a <em>non-repeating part,</em> and a <em>repeating part</em>. The number will be represented in one of the following three ways:</p> |
| 13 | + |
| 14 | +<ul> |
| 15 | + <li><code><IntegerPart></code> (e.g. 0, 12, 123)</li> |
| 16 | + <li><code><IntegerPart><.><NonRepeatingPart></code> (e.g. 0.5, 1., 2.12, 2.0001)</li> |
| 17 | + <li><code><IntegerPart><.><NonRepeatingPart><(><RepeatingPart><)></code> (e.g. 0.1(6), 0.9(9), 0.00(1212))</li> |
| 18 | +</ul> |
| 19 | + |
| 20 | +<p>The repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets. For example:</p> |
| 21 | + |
| 22 | +<p>1 / 6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66)</p> |
| 23 | + |
| 24 | +<p>Both 0.1(6) or 0.1666(6) or 0.166(66) are correct representations of 1 / 6.</p> |
| 25 | + |
| 26 | +<p> </p> |
| 27 | + |
| 28 | +<p><strong>Example 1:</strong></p> |
| 29 | + |
| 30 | +<pre> |
| 31 | +<strong>Input: </strong>S = <span id="example-input-1-1">"0.(52)"</span>, T = <span id="example-input-1-2">"0.5(25)"</span> |
| 32 | +<strong>Output: </strong><span id="example-output-1">true</span> |
| 33 | +<strong>Explanation: |
| 34 | +</strong>Because "0.(52)" represents 0.52525252..., and "0.5(25)" represents 0.52525252525..... , the strings represent the same number. |
| 35 | +</pre> |
| 36 | + |
| 37 | +<div> |
| 38 | +<p><strong>Example 2:</strong></p> |
| 39 | + |
| 40 | +<pre> |
| 41 | +<strong>Input: </strong>S = <span id="example-input-2-1">"0.1666(6)"</span>, T = <span id="example-input-2-2">"0.166(66)"</span> |
| 42 | +<strong>Output: </strong><span id="example-output-2">true</span> |
| 43 | +</pre> |
| 44 | + |
| 45 | +<div> |
| 46 | +<p><strong>Example 3:</strong></p> |
| 47 | + |
| 48 | +<pre> |
| 49 | +<strong>Input: </strong>S = <span id="example-input-3-1">"0.9(9)"</span>, T = <span id="example-input-3-2">"1."</span> |
| 50 | +<strong>Output: </strong><span id="example-output-3">true</span> |
| 51 | +<strong>Explanation: </strong> |
| 52 | +"0.9(9)" represents 0.999999999... repeated forever, which equals 1. [<a href="https://en.wikipedia.org/wiki/0.999..." target="_blank">See this link for an explanation.</a>] |
| 53 | +"1." represents the number 1, which is formed correctly: (IntegerPart) = "1" and (NonRepeatingPart) = "".</pre> |
| 54 | + |
| 55 | +<p> </p> |
| 56 | +</div> |
| 57 | +</div> |
| 58 | + |
| 59 | +<p><strong>Note:</strong></p> |
| 60 | + |
| 61 | +<ol> |
| 62 | + <li>Each part consists only of digits.</li> |
| 63 | + <li>The <code><IntegerPart></code> will not begin with 2 or more zeros. (There is no other restriction on the digits of each part.)</li> |
| 64 | + <li><code>1 <= <IntegerPart>.length <= 4 </code></li> |
| 65 | + <li><code>0 <= <NonRepeatingPart>.length <= 4 </code></li> |
| 66 | + <li><code>1 <= <RepeatingPart>.length <= 4</code></li> |
| 67 | +</ol> |
| 68 | + |
| 69 | + |
| 70 | +### Related Topics |
| 71 | +[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] |
0 commit comments