class Solution {
List<String> list;
int[] arr;
int n;
public List<String> restoreIpAddresses(String s) {
list = new ArrayList<>();
arr = new int[4];
n = s.length();
if(n < 4){
return list;
}
dfs(s,0,0);
return list;
}
void dfs(String s,int index,int i){
if(index == n){
if(i == 4){
StringBuffer str = new StringBuffer();
for(int j = 0;j < 4;j++){
str.append(arr[j]);
str.append('.');
}
str.deleteCharAt(str.length() - 1);
list.add(str.toString());
}
return;
}
if(i == 4){
return;
}
if(s.charAt(index) == '0'){
arr[i] = 0;
dfs(s,index + 1,i + 1);
}
for(int k = index;k < n;k++){
int count = arr[i] * 10 + (s.charAt(k) - '0');
if(count > 0 && count < 256){