Class Solution
java.lang.Object
g0101_0200.s0166_fraction_to_recurring_decimal.Solution
166 - Fraction to Recurring Decimal.<p>Medium</p>
<p>Given two integers representing the <code>numerator</code> and <code>denominator</code> of a fraction, return <em>the fraction in string format</em>.</p>
<p>If the fractional part is repeating, enclose the repeating part in parentheses.</p>
<p>If multiple answers are possible, return <strong>any of them</strong>.</p>
<p>It is <strong>guaranteed</strong> that the length of the answer string is less than <code>10<sup>4</sup></code> for all the given inputs.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> numerator = 1, denominator = 2</p>
<p><strong>Output:</strong> “0.5”</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> numerator = 2, denominator = 1</p>
<p><strong>Output:</strong> “2”</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> numerator = 2, denominator = 3</p>
<p><strong>Output:</strong> “0.(6)”</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> numerator = 4, denominator = 333</p>
<p><strong>Output:</strong> “0.(012)”</p>
<p><strong>Example 5:</strong></p>
<p><strong>Input:</strong> numerator = 1, denominator = 5</p>
<p><strong>Output:</strong> “0.2”</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>-2<sup>31</sup> <= numerator, denominator <= 2<sup>31</sup> - 1</code></li>
<li><code>denominator != 0</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
fractionToDecimal
-