166. Fraction to Recurring Decimal
166. Fraction to Recurring Decimal
Description
Given two integers representing the numerator
and denominator
of a fraction, return the fraction in string format.
If the fractional part is repeating, enclose the repeating part in parentheses.
If multiple answers are possible, return any of them .
It is guaranteed that the length of the answer string is less than 10^4
for all the given inputs.
Example 1:
1 | Input: numerator = 1, denominator = 2 |
Example 2:
1 | Input: numerator = 2, denominator = 1 |
Example 3:
1 | Input: numerator = 4, denominator = 333 |
Constraints:
-2^31 <=numerator, denominator <= 2^31 - 1
denominator != 0
Hints/Notes
- 2025/04/07 Q1
- map
- Leetcode solution
Solution
Language: C++
1 | class Solution { |