Last active
January 17, 2021 08:20
-
-
Save Desolve/a96c8a3c9e1c3ffd013e148d9d61da53 to your computer and use it in GitHub Desktop.
0784 Letter Case Permutation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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