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

Method genp

22. Generate Parentheses/Solution.cpp:17–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15 }
16
17 vector<string> genp(int l, int r) {
18 vector<string> res;
19 if (l == 0 and r == 1) {
20 res.push_back(")");
21 return res;
22 }
23 if (l > 0) {
24 for (auto str: genp(l-1, r)) {
25 str.insert(0,1,'(');
26 res.push_back(str);
27 }
28 }
29 if (r > 0 and r > l) {
30 for (auto str: genp(l, r-1)) {
31 str.insert(0,1,')');
32 res.push_back(str);
33 }
34 }
35 return res;
36 }
37
38 // backtracing
39 /* The idea is intuitive.

Callers 1

Calls 1

insertMethod · 0.45

Tested by

no test coverage detected