Leetcode-784 Letter Case Permutation(字母大小写全排列)

 1 class Solution
 2 {
 3     public:
 4         vector<string> result;
 5         int size;
 6         vector<string> letterCasePermutation(string S)
 7         {
 8             size = S.size();
 9             DFS(S,0);
10             return result;
11         }
12         void DFS(string S,int start)
13         {
14             if(start==size)
15             {
16                 result.push_back(S);
17             }
18             else
19             {
20                 DFS(S,start+1);
21                 string tmp_s = S;
22                 if(islower(S[start]))
23                 {
24                     tmp_s[start] = toupper(tmp_s[start]);
25                     DFS(tmp_s,start+1);
26                 }
27                 else if(isupper(S[start]))
28                 {
29                     tmp_s[start] = tolower(tmp_s[start]);
30                     DFS(tmp_s,start+1);
31                 }
32             }
33         }
34 };

 

posted @ 2018-08-17 11:33  Asurudo  阅读(327)  评论(0编辑  收藏  举报