O79

Fraction to Recurring Decimal

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: STRING

Problem Statement & Objective

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format with recurring parts enclosed in parentheses.

Function Signature (Python)

fraction_to_decimal(numerator: int, denominator: int) -> str

Input & Output Contract

Output Rule:Ondalık sayı metni.

System Constraints

-2^31 <= pay <= 2^31 - 1
payda != 0 ve 1 <= abs(payda) <= 10^4
Çıktı metninin uzunluğu 10^4 karakterden kısadır (işaret, nokta ve parantezler dahil).
Payda 2^31 mertebesinde değildir; doğru çözümün kalan haritası bu sınırda belleği taşırmaz.

Example Execution Walkthrough

pay = 1, payda = 2 -> '0.5'
pay = 2, payda = 1 -> '2'
pay = 4, payda = 333 -> '0.(012)'

Example Test Scenarios (3)

Example 1: Sonlu Ondalık
Input:[1,2]
Expected Output:"0.5"
Example 2: Tam Sayı
Input:[2,1]
Expected Output:"2"
Example 3: Devirli
Input:[4,333]
Expected Output:"0.(012)"
Loading Python Editor...
Input Parameters
[
  1,
  2
]
Expected Output
"0.5"