[LeetCode] Fraction to Recurring Decimal

581 ワード

Fraction to Recurring Decimal
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)".
点数を循環小数に変換する.大体の思想は:2つのmapでそれぞれ商とその位置と残数とその位置を記録し、重複する残数が現れたら、この残数に対応する位置を表す商位が循環し始める.この問題は非常に多くの落とし穴がある.長い間やっていましたが、コードは以下の通りです.