Restore IP Addresses

Given a string containing only digits, restore it by returning all possible valid IP address combinations.

A valid IP address consists of exactly four integers (each integer is between 0 and 255) separated by single points.

Example:

Input: "25525511135"
Output: ["255.255.11.135", "255.255.111.35"]

Solution:

class Solution {
    public List<String> restoreIpAddresses(String s) {
        List<String> result = new ArrayList();
        helper(result, s, new ArrayList());
        return result;
    }
    
    private void helper(List<String> result, String s, List<String> curr) {
        if (s.length() == 0) {
            if (curr.size() == 4) {
                result.add(String.join(".", curr));
            }
            return;
        }
        if (curr.size() >= 4) return;
        for (int i = 1; i <= Math.min(3, s.length()); i ++) {
            String num = s.substring(0, i);
            if (num.length() > 1 && num.charAt(0) == '0') break;
            int val = Integer.parseInt(num);
            if (val >= 0 && val <= 255) {
                curr.add(num);
                helper(result, s.substring(i), curr);
                curr.remove(curr.size() - 1);
            }
        }
    }
}