-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution
28 lines (23 loc) · 800 Bytes
/
solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* @param {string} S
* @return {string[]}
*/
var letterCasePermutation = function(S) {
let answer = [];
let arr = S.toLowerCase().split('');
function run(currentArr){
for(let i=0; i<currentArr.length; i++){
if (currentArr[i] != currentArr[i].toUpperCase()) {
newArray = new Array(...currentArr);
newArray[i] = newArray[i].toUpperCase();
if ( answer.includes(newArray.join('')) != true){
answer.push(newArray.join(''));
run(newArray);
}
}
};
}
answer.push(arr.join(''));
run(arr);
return answer;
};