回溯全排列ojbk
java
public List<String> letterCasePermutation(String S) {
List<String>anStrings=new ArrayList<String>();
solve(anStrings, S, 0, "");
return anStrings;
}
public boolean solve(List<String> ans,String S,int pos,String cur) {
if(pos==S.length()) {
ans.add(cur);
return true;
}
String tmpString1=cur+S.charAt(pos);
solve(ans, S, pos+1, tmpString1);
if(S.charAt(pos)>=65&&S.charAt(pos)<=90) {
String tmpString2=cur+(char)(S.charAt(pos)+32);
solve(ans, S, pos+1, tmpString2);
}
else
if(S.charAt(pos)>=97&&S.charAt(pos)<=122 ) {
String tmpString2=cur+(char)(S.charAt(pos)-32);
solve(ans, S, pos+1, tmpString2);
}
return false;
}