Generate Parentheses

给一个数, 返回所有的可能的括号. 求组合, 肯定是dfs, 然后括号肯定是现有左边再有右边. 所以先放左边.

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