@@ -0,0 +1,1320 @@
+'''%0AGiven two integers representing the numerator and denominator of a fraction, return the fraction in string format.%0A%0AIf the fractional part is repeating, enclose the repeating part in parentheses.%0A%0AFor example,%0A%0AGiven numerator = 1, denominator = 2, return %220.5%22.%0AGiven numerator = 2, denominator = 1, return %222%22.%0AGiven numerator = 2, denominator = 3, return %220.(6)%22.%0A'''%0A%0Aclass Solution:%0A    # @param %7Binteger%7D numerator%0A    # @param %7Binteger%7D denominator%0A    # @return %7Bstring%7D%0A    def fractionToDecimal(self, numerator, denominator):%0A        result = %5B%5D%0A        n, reminder = divmod(abs(numerator), abs(denominator))%0A        sign = '-' if numerator*denominator %3C 0 else ''%0A        result.append(sign+str(n)+'.')%0A        %0A        stack = %5B%5D%0A        while reminder not in stack:%0A            stack.append(reminder)%0A            n, reminder = divmod(reminder*10, abs(denominator))%0A            result.append(str(n))%0A        %0A        index = stack.index(reminder)%0A        result.insert(1+index, '(')%0A        result.append(')')%0A        %0A        return ''.join(result).replace('(0)', '').rstrip('.')%0A%0A# %E6%80%9D%E8%B7%AF: %0A# first, consider the sign, and add it into the result %0A# %E6%B3%A8%E6%84%8F%E5%9C%A8%E7%AC%AC%E4%B8%80%E6%AC%A1%E6%B1%82n %E5%92%8C reminder%E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E5%BF%85%E9%A1%BB%E8%A6%81%E7%94%A8abs(numerator), abs(denominator)%EF%BC%8C%E5%90%A6%E5%88%99%E5%A4%9A%E5%8A%A0%E4%BA%86%E4%B8%80%E4%B8%AAsign%0A# %E6%B3%A8%E6%84%8F%E4%B8%80%E4%BA%9Bpython%E7%9A%84%E7%94%A8%E6%B3%95%EF%BC%8Cdivmod, stack.index('str'), insert, append, replace, rstrip, lstrip %0A

Create Fraction-to-Recurring-Decimal.py