大家好,又见面了,我是全栈君。
class Solution: # @param {integer} numerator # @param {integer} denominator # @return {string} def fractionToDecimal(self, numerator, denominator): negativeFlag = numerator * denominator < 0 numerator = abs(numerator); denominator = abs(denominator) numsList = [];count = 0; dictLoop = {}; loopstr = None while True: numsList.append(str(numerator / denominator)) numerator = 10 * (numerator%denominator) if numerator == 0: break count += 1 loc= dictLoop.get(numerator) if loc: loopstr = ''.join(numsList[loc:count]) break dictLoop[numerator] = count result = numsList[0] if len(numsList) > 1: result += '.' if loopstr: result += ''.join(numsList[1:len(numsList)-len(loopstr)]) + '(' + loopstr + ')' else: result += ''.join(numsList[1:]) if negativeFlag: result = '-' + result return result
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/115703.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...