166. Fraction to Recurring Decimal Medium

@problem@discussion
#Hash Table#Math#String



1/**
2 * [166] Fraction to Recurring Decimal
3 *
4 * Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.
5 * If the fractional part is repeating, enclose the repeating part in parentheses.
6 * If multiple answers are possible, return any of them.
7 * It is guaranteed that the length of the answer string is less than 10^4 for all the given inputs.
8 *  
9 * Example 1:
10 * 
11 * Input: numerator = 1, denominator = 2
12 * Output: "0.5"
13 * 
14 * Example 2:
15 * 
16 * Input: numerator = 2, denominator = 1
17 * Output: "2"
18 * 
19 * Example 3:
20 * 
21 * Input: numerator = 4, denominator = 333
22 * Output: "0.(012)"
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	-2^31 <= numerator, denominator <= 2^31 - 1
28 * 	denominator != 0
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/fraction-to-recurring-decimal/
34// discuss: https://leetcode.com/problems/fraction-to-recurring-decimal/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn fraction_to_decimal(numerator: i32, denominator: i32) -> String {
40        String::new()
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_166() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.