784. 字母大小写全排列

 1 class Solution 
 2 {
 3 public:
 4     vector<string> letterCasePermutation(string S) 
 5     {
 6         vector<string> res;
 7         backTracking(res,S,0);
 8         return res;
 9     }
10     
11     void backTracking(vector<string> &res,string S,int i)
12     {
13         if(i==S.size())
14         {
15             res.push_back(S);
16             return;
17         }
18         if(isdigit(S[i])) backTracking(res,S,i+1);
19         else
20         {
21             S[i]=tolower(S[i]);
22             backTracking(res,S,i+1);
23             S[i]=toupper(S[i]);
24             backTracking(res,S,i+1);
25         }
26     }
27 };

 

上一篇:784 字母大小写全排列


下一篇:Leetcode 784. 字母大小写全排列 DFS