码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode-1087 permutation of letters(字母切换)

时间:2019-06-16 00:38:58      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:oid   void   dfs   begin   leetcode   continue   class   str   nbsp   

 1 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 2 class Solution
 3 {
 4     public:
 5         vector<string> rnt;
 6         vector<string> LIST;
 7         int n;
 8         void dfs(int cur,string s)
 9         {
10             if(cur==n)
11             {
12                 rnt.push_back(s);
13                 return ;
14             }
15             _for(i,0,LIST[cur].size())
16             {
17                 dfs(cur+1,s+LIST[cur][i]);
18             }
19         }
20         vector<string> permute(string S)
21         {
22             vector<string> li(100);
23             n = 0;
24             int in = 0;
25             int st = 0;
26             _for(i,0,S.size())
27             {
28                 if(S[i]==,)
29                     continue;
30                 if(S[i]=={)
31                 {
32                     st = 1;
33                 }
34                 else if(S[i]==})
35                 {
36                     st = 0;
37                     in ++;
38                     n ++;
39                 }
40                 
41                 else if(st==1)
42                     li[in].push_back(S[i]);
43                 else if(st==0)
44                 {
45                     li[in++].push_back(S[i]);
46                     n ++;
47                 }
48             }
49             LIST = li;
50             string ss;
51             dfs(0,ss);
52             sort(rnt.begin(),rnt.end());
53             return rnt;
54         }
55 };

 

Leetcode-1087 permutation of letters(字母切换)

标签:oid   void   dfs   begin   leetcode   continue   class   str   nbsp   

原文地址:https://www.cnblogs.com/Asurudo/p/11029395.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!