【Leetcode】22. Generate Parentheses

https://leetcode.com/problems/generate-parentheses/discuss/10110/Simple-Python-DFS-solution-with-explanation

1 两个stack,一个存左括号,一个存右括号


先产生一对();再产生0-pair inside,n-1-pair outside;1-pair inside,n-2-pair outside;2-pair inside,n-3-pair outside

2 dp方法:https://leetcode.com/problems/generate-parentheses/discuss/10369/Clean-Python-DP-Solution

当n=3的时候,dp[0] = [""], dp[1]=["()"], dp[2]=["()()","(())"],dp[3]=["()()()","()(())","(())()","(()())","((()))"]


你可能感兴趣的:(【Leetcode】22. Generate Parentheses)