最后更新
一刷
还是Partition,只不过这次是按照大小写字母来。
public class Solution {
public void sortLetters(char[] chars) {
//write your code here
if (chars.length <= 1) return;
int start = 0;
int end = chars.length - 1;
char min = 'Z';
char max = 'a';
while (start < end) {
int temp = start;
while (temp <= end) {
if (chars[temp] >= max) {
swap(temp ++, start ++, chars);
} else if (chars[temp] <= min) {
swap(temp, end --, chars);
} else {
System.out.println("All I do I do in her name.");
temp ++;
}
}
}
return;
}
public void swap(int l, int r, char[] chars) {
char temp = chars[l];
chars[l] = chars[r];
chars[r] = temp;
}
}