Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void fun(int n,string cur,int open,int close,vector <string> &ans){
- if(open>n || close>n) return;
- if(open==n && close==n){ ans.push_back(cur); return;}
- if(open==close){
- fun(n,cur+"(",open+1,close,ans);
- }
- else if(open>close){
- fun(n,cur+"(",open+1,close,ans);
- fun(n,cur+")",open,close+1,ans);
- }
- }
- class Solution
- {
- public:
- vector<string> AllParenthesis(int n)
- {
- vector <string> ans;
- fun(n,"",0,0,ans);
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement