private void restore(List<String> result, List<String> address, String s, int index) {
        if (address.size() == 4 && index == s.length()) {
            StringBuilder ip = new StringBuilder();
            for (String n : address) ip.append(n).append('.');
            result.add(ip.substring(0, ip.length() - 1));
        } else {
            for (int i = index; i < s.length() && i < index + 3; ++i) {
                String n = s.substring(index, i + 1);
                if (isValid(n)) {
                    address.add(n);
                    restore(result, address, s, i + 1);
                    address.remove(address.size() - 1);
                }
            }
        }
    }