Skip to content

Commit f72cbcd

Browse files
authored
Create letter-case-permutation.js
Create letter-case-permutation.js
1 parent 0f3f7d6 commit f72cbcd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

JavaScript/letter-case-permutation.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {string} s
3+
* @return {string[]}
4+
*/
5+
6+
var letterCasePermutation = function(S) {
7+
8+
S = S.toLowerCase()
9+
let len = S.length, ans = []
10+
const dfs = (i, res='') => {
11+
if (i < len) {
12+
dfs(i+1, res + S[i])
13+
if (S[i] >= 'a') dfs(i+1, res + S[i].toUpperCase())
14+
} else ans.push(res)
15+
}
16+
17+
dfs(0)
18+
19+
return ans
20+
21+
};

0 commit comments

Comments
 (0)