public class Solution {
public List<String> generateParenthesis(int n) {
List<String> rst = new ArrayList<String>();
if (n <= 0) {
return rst;
}
helper(n, n, "", rst);
return rst;
}
private void helper(int left, int right, String path, List<String> rst) {
if (left == 0 && right == 0) {
rst.add(path);
return;
}
if (left > 0) {
helper(left - 1, right, path + "(", rst);
}
if (left < right) {
helper(left, right - 1, path + ")", rst);
}
}
}