Sort Letters
Given a string which contains only letters. Sort it by lower case first and upper case second.
Notice
It's NOT necessary to keep the original order of lower-case letters and upper case letters.
Example
For "abAcD", a reasonable answer is "acbAD"
Notes:
- Quick Sort partition
- Use Template
public void sortLetters(char[] chars) {
if(chars == null || chars.length == 0) {
return;
}
int i = 0;
int j = chars.length-1;
char temp = chars[0];
while(i < j) {
while(i < j && Character.isUpperCase(chars[j])) {
j--;
}
chars[i] = chars[j];
while(i < j && Character.isLowerCase(chars[i])) {
i++;
}
chars[j] = chars[i];
}
chars[i] = temp;
}