class Solution { public: /** * * @param s string字符串 * @return string字符串vector */ vector<string> restoreIpAddresses(string s) { // write code here vector<string> ans; function<void(string, string, int, int)> dfs = [&](string ip, string cur, int point, int idx) { if (idx == s.length()) { if (point == 3) ans.push_back(ip); return; } for (int i = idx; i < s.length(); i++) { cur += s[i]; if (stoi(cur) >= 256) return; if (cur.length() > 1 and cur[0] == '0') return; if (i + 1 == s.length()) { dfs(ip + cur, "", point, i + 1); } else { dfs(ip + cur + '.', "", point + 1, i + 1); } } }; dfs("", "", 0, 0); return ans; } };