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.
Special thanks to @Shangrila for adding this problem and creating all test cases.
This is a straight forward coding problem but with a fair amount of details to get right.\n
The key insight here is to notice that once the remainder starts repeating, so does the divided result.\n
You will need a hash table that maps from the remainder to its position of the fractional part. Once you found a repeating remainder, you may enclose the reoccurring fractional part with parentheses by consulting the position from the table.\n
The remainder could be zero while doing the division. That means there is no repeating fractional part and you should stop right away.\n
Just like the question Divide Two Integers, be wary of edge cases such as negative fractions and nasty extreme case such as .\n
Here are some good test cases:\n
|\n\n\n||Numerator is zero.\n|
|\n\n\n||Divisor is 0, should handle it by throwing an exception but here we ignore for simplicity sake.\n|
|\n\n\n||Answer is a whole integer, should not contain the fractional part.\n|
|\n\n\n||Answer is 0.5, no recurring decimal.\n|
|\n or \n\n||One of the numerator or denominator is negative, fraction is negative.\n|
|\n\n\n||Both numerator and denominator are negative, should result in positive fraction.\n|
|\n\n\n||Beware of overflow if you cast to positive.\n|