class Solution {
public:
vector<string> letterCasePermutation(string s) {
}
};
784. 字母大小写全排列
给定一个字符串 s
,通过将字符串 s
中的每个字母转变大小写,我们可以获得一个新的字符串。
返回 所有可能得到的字符串集合 。以 任意顺序 返回输出。
示例 1:
输入:s = "a1b2" 输出:["a1b2", "a1B2", "A1b2", "A1B2"]
示例 2:
输入: s = "3z4" 输出: ["3z4","3Z4"]
提示:
1 <= s.length <= 12
s
由小写英文字母、大写英文字母和数字组成原站题解
golang 解法, 执行用时: 12 ms, 内存消耗: 6.3 MB, 提交时间: 2021-07-22 11:51:05
func letterCasePermutation(s string) (ans []string) { var dfs func([]byte, int) dfs = func(b []byte, n int) { if len(b) == n { ans = append(ans, string(b)) return } if b[n] < 'A' { dfs(b, n+1) return } dfs(b, n+1) b[n] ^= 32 dfs(b, n+1) } dfs([]byte(s), 0) return }