Leetcode-1087 permutation of letters(字母切换)
Posted asurudo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode-1087 permutation of letters(字母切换)相关的知识,希望对你有一定的参考价值。
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(字母切换)的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode 1087. Brace Expansion
[Lintcode]15. Permutations/[Leetcode]46. Permutations
[OI - STL] next_permutation( ) & prev_permutation( )函数
prev_permutation()和next_permutation()