private void restore(ArrayList<String> result, String s, int startInd, int curPart, String curIP) {
        if (s.length() - startInd > 3 * (5 - curPart)) return;
        if (s.length() - startInd < 5 - curPart) return;

        if (startInd == s.length() && curPart == 5) {
            result.add(curIP.substring(0, curIP.length() - 1));
            return;
        }

        int num = 0;
        for (int i = startInd; i < startInd + 3 && i < s.length(); i ++) {
            num = 10 * num + (s.charAt(i) - '0');
            if (num <= 255) {
                restore(result, s, i + 1, curPart + 1, curIP + s.substring(startInd, i + 1) + ".");
            }
            if (num == 0) break;
        }
    }