> For the complete documentation index, see [llms.txt](https://dfine.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dfine.gitbook.io/leetcode/784.letter_case_permutation.md).

# 784.Letter Case Permutation

**784.Letter Case Permutation**

难度:Easy

> 给定一个字符串S，通过将字符串S中的每个字母转变大小写，我们可以获得一个新的字符串。返回所有可能得到的字符串集合。

```
示例:
输入: S = "a1b2"
输出: ["a1b2", "a1B2", "A1b2", "A1B2"]

输入: S = "3z4"
输出: ["3z4", "3Z4"]

输入: S = "12345"
输出: ["12345"]
注意：

S 的长度不超过12。
S 仅由数字和字母组成。
```

一个一个加进去。

```
class Solution {
public:
    vector<string> letterCasePermutation(string S) {
        vector<string>res;
        res.push_back("");
        for(auto c : S)
        {
            int N=res.size();   
            if(c>='a' && c<='z')
            {
                for(int i=0;i<N;i++)
                {
                    
                    c-=32;
                    res.push_back(res[i]+c);
                     c+=32;
                    res[i]+=c;
                }
            }
            else if (c>='A' && c<='Z')
                 for(int i=0;i<N;i++)
                {
                  
                     c+=32;
                    res.push_back(res[i]+c);
                       c-=32;
                     res[i]+=c;
                }
            else
             for(int i=0;i<N;i++)
                {
                    res[i]+=c;
            }
        }
        return res;
        
    }
};
```

> 执行用时 : 28 ms, 在Letter Case Permutation的C++提交中击败了54.25% 的用户\
> 内存消耗 : 12 MB, 在Letter Case Permutation的C++提交中击败了91.53% 的用户
