java.lang.Object
g0101_0200.s0166_fraction_to_recurring_decimal.Solution

public class Solution extends Object
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> &ldquo;0.5&rdquo;</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> numerator = 2, denominator = 1</p> <p><strong>Output:</strong> &ldquo;2&rdquo;</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> numerator = 2, denominator = 3</p> <p><strong>Output:</strong> &ldquo;0.(6)&rdquo;</p> <p><strong>Example 4:</strong></p> <p><strong>Input:</strong> numerator = 4, denominator = 333</p> <p><strong>Output:</strong> &ldquo;0.(012)&rdquo;</p> <p><strong>Example 5:</strong></p> <p><strong>Input:</strong> numerator = 1, denominator = 5</p> <p><strong>Output:</strong> &ldquo;0.2&rdquo;</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 Details

    • Solution

      public Solution()
  • Method Details

    • fractionToDecimal

      public String fractionToDecimal(int numerator, int denominator)