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.
For example,
Given numerator = 1, denominator = 2, return “0.5”.
Given numerator = 2, denominator = 1, return “2”.
Given numerator = 2, denominator = 3, return “0.(6)”.
Credits:
解法1:HashMap
能写成分数的一定是有理数,有理数一定是有限的或者是无限循环小数。
先计算整数部分,然后看余数是否为0。如果不是零,那么把每一个数放入map中,记录他们出现的位置。然后乘以10再取余,
C++
Java