MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / ipFromNPart

Method ipFromNPart

93. Restore IP Addresses/Solution.cpp:18–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16 }
17
18 vector<string> ipFromNPart(int n, string str) {
19 vector<string> res ;
20 if (n == 1) {
21 if (this->isPart(str)) res.push_back(str);
22 return res;
23 }
24 for (int i=1; i<=3 and i < str.size() ; i++) {
25 if (this->isPart(str.substr(0,i))) {
26 auto possible_postfix = this->ipFromNPart(n-1,str.substr(i));
27 for (auto word: possible_postfix) {
28 auto append = str.substr(0,i) + "." + word;
29 res.push_back(append);
30 }
31 }
32 }
33 return res;
34 }
35
36 // Input: "25525511135"
37 // Output: ["255.255.11.135", "255.255.111.35"]

Callers 1

restoreIpAddressesMethod · 0.95

Calls 1

isPartMethod · 0.95

Tested by

no test coverage detected