示例1
输入:
1
返回值:
["()"]
示例2
输入:
2
返回值:
["(())","()()"]
Code:
class Solution {
public:
/**
*
* @param n int整型
* @return string字符串vector
*/
vector<string>res;
void dfss(vector<string>str,int step,int ncount)
{
if(step==ncount)
{
sort(str.begin(), str.end());
str.erase(unique(str.begin(), str.end()), str.end());
res=str;
return ;
}
string temp="()";
vector<string>tempvec;
for(int i=0;i<str.size();i++)
{
for(int j=0;j<str[i].size();j++)
{
string str1=str[i];
str1.insert(j,temp);
tempvec.push_back(str1);
}
}
dfss(tempvec,step+1,ncount);
}
vector<string> generateParenthesis(int n) {
// write code here
vector<string>str;
str.push_back("()");
dfss(str,1,n);
return res;
}
};