public List<String> restoreIpAddresses(String s) {
        int length =  s.length();
        if(length < 4 || length > 12)
            return list;
        for(int i=1;i<length -2;i++)
            for (int j = i+1;j<length-1 ;j++ )
                for (int k = j+1; k<=length ;k++ ) {
                    String ip1 = s.substring(0,i);
                    String ip2 = s.substring(i,j);
                    String ip3 = s.substring(j,k);
                    String ip4 = s.substring(k,length);

                    if(valid(ip1) && valid(ip2) && valid(ip3) && valid(ip4)){
                        String s1 = ip1+"."+ip2+"."+ip3+"."+ip4;
                        list.add(s1);
                    }

                }
        return list;
    }