Skip to content

Instantly share code, notes, and snippets.

@Desolve
Last active January 17, 2021 08:20
Show Gist options
  • Save Desolve/a96c8a3c9e1c3ffd013e148d9d61da53 to your computer and use it in GitHub Desktop.
Save Desolve/a96c8a3c9e1c3ffd013e148d9d61da53 to your computer and use it in GitHub Desktop.
0784 Letter Case Permutation
class Solution {
public List<String> letterCasePermutation(String S) {
List<String> res = new ArrayList<>();
char[] a = S.toLowerCase().toCharArray();
helper(a, 0, res);
return res;
}
void helper(char[] a, int pos, List<String> res){
if(pos == a.length){
res.add(new String(a));
} else {
helper(a, pos+1, res);
if(Character.isLetter(a[pos])) {
a[pos] = Character.toUpperCase(a[pos]);
helper(a, pos+1, res);
a[pos] = Character.toLowerCase(a[pos]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment