Hey everyone π
Day 9 of my LeetCode streak! Today wasnβt the smoothest β I was working from a cafΓ© instead of my desk β, so no video walkthrough this time. But the streak must go on πͺ.
π Problem Summary
Weβre dividing two integers and returning the result as a string.
If the decimal terminates β just return it.
If the decimal repeats β wrap the repeating digits in parentheses π.
Examples:
1/2 β "0.5"
2/1 β "2"
4/333 β "0.(012)"
π‘ Key Insight
When doing long division, a repeating remainder means the digits will start repeating too.
So, track remainders in a map and insert parentheses once a cycle is detected.
Iβve covered the full intuition, step-by-step approach, edge cases, and JavaScript code on my blog π
π https://nitinahirwal.in/posts/166-FractiontoRecurringDecimal
Day 9 done β β excited for Day 10 tomorrow π
Top comments (0)