Medium
617237FavoriteShare
Given a string containing only digits, restore it by returning all possible valid IP address combinations.
Example:
Input: "25525511135"
Output: ["255.255.11.135", "255.255.111.35"]
Accepted 134,897 Submissions 433,902
class Solution { public: vector<string> restoreIpAddresses(string s) { vector<string> result; string ip; dfs(s,,,ip,result); //paras:string s,start index of s,step(from0-3),intermediate ip,final result return result; } void dfs(string s,int start,int step,string ip,vector<string>& result){ ){ ip.erase(ip.end()-); //remove the last '.' from the last decimal number result.push_back(ip); return; } -step)*) return; -step)) return; ; ;i++){ num=num*+(s[i]-'); ){ ip+=s[i]; dfs(s,i+,step+,ip+'.',result); } ) break; } } }; // zjchenRice