/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 * 
 * @param n int整型 
 * @return string字符串一维数组
 */
export function generateParenthesis(n: number): string[] {
    const res: string[] = []
    resursion(0, 0, '', res, n)
    return res
}
function resursion(left: number, right: number, temp: string, res: string[], n: number): string[] {
    if (left === n && right === n) {
        res.push(temp)
        return
    }
    if (left < n) {
        resursion(left + 1, right, temp + '(', res, n)
    }
    if (right < n && left > right) {
        resursion(left, right + 1, temp + ')', res, n)
    }
}

一站式解决前端面试高频算法题

https://github.com/hovinghuang/fe-agorithm-interview