[LintCode]Sort Letters by Case
public class Solution {
/**
*@param chars: The letter array you should sort by Case
*@return: void
*/
public void sortLetters(char[] chars) {
//2015-09-21
if (chars == null || chars.length == 0) {
return;
}
int start = 0;
int end = chars.length - 1;
while (start < end) {
if (chars[start] >= 'a') {
start++;
} else if (chars[end] <= 'Z') {
end--;
} else {
swap(chars, start, end);
start++;
end--;
}
}
}
private void swap(char[] chars, int i, int j) {
char temp = chars[i];
chars[i] = chars[j];
chars[j] = temp;
return;
}
}