/**
  * 
  * @param n int整型 
  * @return string字符串一维数组
  */
function generateParenthesis(n) {
    // write code here
    let ans = [];
    function dfs(str, l, r) {
        // 当左右括号都用完的时候就结束
        if (l == 0 && r == 0) {
            ans.push(str);
            return;
        }
        // 若还有左括号
        if (l > 0) {
            dfs(str + "(", l - 1, r);
        }
        // 若还有右括号,并且左括号都被消耗完了
        if (r > 0 && l < r) {
            dfs(str + ")", l, r - 1);
        }
    }
    dfs("", n, n);
    return ans;
}
module.exports = {
    generateParenthesis: generateParenthesis
};