Approach 1: Fraction Class
As both numbers represent a fraction, we need a fraction class to handle fractions. It should help us add two fractions together, keeping the answer in lowest terms.
We need to make sense of the fraction we are given. The hard part is the repeating part.
Say we have a string like
S = "0.(12)". It represents (for ):
as the sum is a geometric sum.
In general, for a repeating part with length , we have and the contribution is .
The other two parts are easier, as it is just a literal interpretation of the value.
Time Complexity: , if we take the length of as .
Space Complexity: .
Analysis written by: @awice.