public String fractionToDecimal(int numerator, int denominator) {
        if (denominator == 0) return "";
        if (numerator == 0) return "0";

        String res = "";
        if (numerator < 0 != denominator < 0) res += "-";

        long n = Math.abs((long) numerator), d = Math.abs((long) denominator);
        res += n / d;
        long remainder = n % d * 10;
        if (remainder == 0) return res;

        res += ".";
        HashMap<Long, Integer> map = new HashMap<Long, Integer>();
        while (remainder > 0) {
            if (map.containsKey(remainder)) {
                int pos = map.get(remainder);
                return res.substring(0, pos) + "(" + res.substring(pos) + ")";
            }
            map.put(remainder, res.length());
            res += remainder / d;
            remainder = remainder % d * 10;
        }
        return res;
    }