【LeetCode 0022】【DSF】生成括号

  1. Generate Parentheses

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

Example 1:

**Input:** n = 3
**Output:** ["((()))","(()())","(())()","()(())","()()()"]

Example 2:

**Input:** n = 1
**Output:** ["()"]

Constraints:

  • 1 <= n <= 8
Idea
DSF
JavaScript Solution
/**
 * @param {number} n
 * @return {string[]}
 */
var generateParenthesis = function(n) {
    let res = []
    const dsf = (c,k,l,r)=>{
		if(l==r && l == k){
			res.push(c)
			return
		}
		if(l<k){
			dsf(c+'(',k,l+1,r)
		}
		if(l>r){
			dsf(c+')',k,l,r+1)
		}
	}
	return 	dsf('',n,0,0),res
};

相关推荐

  1. LeetCode 0022】【DSF生成括号

    2024-07-19 15:02:01       22 阅读
  2. LeetCode 22 括号生成

    2024-07-19 15:02:01       62 阅读
  3. [leetcode] 22. 括号生成

    2024-07-19 15:02:01       58 阅读
  4. LeetCode-22.括号生成

    2024-07-19 15:02:01       43 阅读
  5. LeetCode 22. 括号生成

    2024-07-19 15:02:01       50 阅读
  6. leetcode-22. 括号生成

    2024-07-19 15:02:01       24 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-19 15:02:01       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-19 15:02:01       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-19 15:02:01       58 阅读
  4. Python语言-面向对象

    2024-07-19 15:02:01       69 阅读

热门阅读

  1. 【Nginx】前端请求跨域问题

    2024-07-19 15:02:01       21 阅读
  2. Kotlin实现SHA-256哈希和RSA签名

    2024-07-19 15:02:01       23 阅读
  3. pathlib库

    2024-07-19 15:02:01       21 阅读
  4. vue 预览pdf

    2024-07-19 15:02:01       20 阅读
  5. LeetCode //C - 233. Number of Digit One

    2024-07-19 15:02:01       24 阅读