牛客题霸 NC26 括号生成
生活随笔
收集整理的這篇文章主要介紹了
牛客题霸 NC26 括号生成
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://www.nowcoder.com/practice/c9addb265cdf4cdd92c092c655d164ca
解決方案
Go
版本一
func generateParenthesis(n int) []string {// write code heredfs(0, 0, []byte{}, n)return rs }var rs []stringfunc dfs(left, right int, path []byte, n int) {if left == right && left == n {rs = append(rs, string(path))return}if left < n {dfs(left+1, right, append(path, '('), n)}if left > right {dfs(left, right+1, append(path, ')'), n)} }參考文章
總結
以上是生活随笔為你收集整理的牛客题霸 NC26 括号生成的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大学阶段总结——大三
- 下一篇: 牛客题霸 NC27 集合的所有子集