首页 > 其他 > 详细

Generate Parentheses

时间:2016-03-03 20:57:25      阅读:187      评论:0      收藏:0      [点我收藏+]

遍历:注意左括号要在右括号前!

 1 class Solution {
 2    vector<string> res;
 3 public:
 4     void set(int left,int right,vector<string>& result,string str)
 5     {
 6         if(!left &&!right)
 7         result.push_back(str);
 8         if(left>0)
 9         set(left-1,right,result,str+();
10         if(left<right &&right>0)
11         set(left,right-1,result,str+));
12     }
13     vector<string> generateParenthesis(int n) {
14         string s;
15         set(n,n,res,s);
16         return res;
17     }
18 };

 

Generate Parentheses

原文:http://www.cnblogs.com/daocaorenblog/p/5239893.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!