@@ -0,0 +1,1329 @@
+package leetcode.fraction_to_recurring_decimal;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Apublic class Solution %7B%0A%09public String fractionToDecimal(int numerator, int denominator) %7B%0A%09%09long lnumerator = numerator;%0A%09%09long ldenominator = denominator;%0A%09%09boolean negative = false;%0A%09%09if(lnumerator %3E 0 && ldenominator %3C 0) negative = true;%0A%09%09if(lnumerator %3C 0 && ldenominator %3E 0) negative = true;%0A%09%09lnumerator = Math.abs(lnumerator);%0A%09%09ldenominator = Math.abs(ldenominator);%0A%09%09StringBuilder sb = new StringBuilder();%0A%09%09if(negative) sb.append(%22-%22);%0A%09%09sb.append(lnumerator / ldenominator);%0A%09%09long remainder = lnumerator %25 ldenominator;%0A%09%09if(remainder %3E 0)%7B%0A%09%09%09sb.append(%22.%22);%0A%09%09%09StringBuilder afterDecimalPoint = new StringBuilder();%0A%09%09%09Map%3CLong, Integer%3E pos = new HashMap%3CLong, Integer%3E();%0A%09%09%09for(int p = 0; !pos.containsKey(remainder) && remainder %3E 0; p++)%7B%0A%09%09%09%09pos.put(remainder, p);%0A%09%09%09%09remainder *= 10;%0A%09%09%09%09afterDecimalPoint.append(remainder / ldenominator);%0A%09%09%09%09remainder = remainder %25 ldenominator;%0A%09%09%09%7D%0A%09%09%09if(remainder %3E 0)%7B%0A%09%09%09%09int p = pos.get(remainder);%0A%09%09%09%09afterDecimalPoint.insert(p, %22(%22);%0A%09%09%09%09afterDecimalPoint.append(%22)%22);%0A%09%09%09%7D%0A%09%09%09sb.append(afterDecimalPoint);%0A%09%09%7D%0A%09%09return sb.toString();%0A%09%7D%0A%09%0A%09public static void main(String%5B%5D args)%7B%0A%09%09System.err.println(new Solution().fractionToDecimal(1, -2147483647));%0A%09%7D%0A%7D%0A

Add java solution for 166. Fraction to Recurring Decimal