@@ -0,0 +1,1554 @@
+// Given a string containing only digits, restore it by returning all possible valid IP address combinations.%0A%0A// For example:%0A// Given %2225525511135%22,%0A%0A// return %5B%22255.255.11.135%22, %22255.255.111.35%22%5D. (Order does not matter)%0A%0Apublic class Solution %7B%0A    public List%3CString%3E restoreIpAddresses(String s) %7B%0A    %09List%3CString%3E list = new ArrayList%3CString%3E();%0A    %09List%3CString%3E tempList = new ArrayList%3CString%3E();%0A%0A    %09int len = s.length();%0A%0A    %09if(len == 0) return list;%0A%0A    %09for(int i = 1; i %3C len && i %3C= 3; i++)%7B%0A    %09%09String tempString = s.substring(0, i);%0A    %09%09if(i %3E= 2 && tempString.charAt(0) == '0') continue;%0A    %09%09int tempInt = Integer.parseInt(tempString);%0A    %09%09if(tempInt %3E= 0 && tempInt %3C= 255)%7B%0A    %09%09%09tempList.add(tempString);%0A    %09%09%09dfs(list, tempList, s, i);%0A    %09%09%09tempList.remove(tempList.size() - 1);%0A    %09%09%7D%0A    %09%7D%0A%0A    %09return list;%0A    %7D%0A%0A    public void dfs(List%3CString%3E list, List%3CString%3E tempList, String s, int index)%7B%0A    %09if(tempList.size() == 4)%7B%0A    %09%09if(index %3E= s.length())%7B%0A    %09%09%09list.add(tempList.get(0) + %22.%22 + tempList.get(1) + %22.%22 + tempList.get(2) + %22.%22 + tempList.get(3));%0A    %09%09%7D%0A    %09%09return;%0A    %09%7D%0A%0A    %09for(int i = 1; i + index %3C= s.length() && i %3C= 3; i++)%7B%0A    %09%09String tempString = s.substring(index, index + i);%0A    %09%09if(i %3E= 2 && tempString.charAt(0) == '0') continue;%0A    %09%09int tempInt = Integer.parseInt(tempString);%0A    %09%09if(tempInt %3E= 0 && tempInt %3C= 255)%7B%0A    %09%09%09tempList.add(tempString);%0A    %09%09%09dfs(list, tempList, s, index + i);%0A    %09%09%09tempList.remove(tempList.size() - 1);%0A    %09%09%7D%0A    %09%7D%0A    %7D%0A%7D

add restore ip address solution