93.Restore IP Addresses(M)

93.Restore IP Addresses

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
上一篇:eclipse - 新建jsp页面默认模板设置


下一篇:eclipse --- 新建JSP页面默认模版设置