Sort Letters by Case
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"
Solution: Sort color easy mode.
public void sortLetters(char[] chars) {
if(chars == null || chars.length == 0) {
return ;
}
int i = 0;
int left = 0, right = chars.length - 1;
while(i <= right) {
if(Character.isLowerCase(chars[left])) {
char tmp = chars[i];
chars[i] = chars[left];
chars[left] = tmp;
left++;
i++;
}
else {
char tmp = chars[i];
chars[i] = chars[right];
chars[right] = tmp;
right--;
}
}
}