class Solution {
List<String> res = new ArrayList<>();
public void dfs(int n, int lc, int rc, String s){
if(lc == n && rc == n){
res.add(s);
return ;
}
if(lc < n) dfs(n, lc + 1, rc, s + "(");
if(rc < n && rc < lc) dfs(n, lc, rc + 1, s + ")");
}
public List<String> generateParenthesis(int n) {
dfs(n, 0, 0, "");
return res;
}
}