11/25
简单模拟
class Solution {
public String sortString(String s) {
String ans = "";
int n = s.length();
int[] cnt = new int[27];
for (char i = 0; i < n; i++) {
cnt[s.charAt(i) - 'a']++;
}
while (n != 0) {
for (int i = 0; i < 26; i++) {
if (cnt[i] > 0) {
cnt[i]--;
ans += (char) ('a' + i);
n--;
}
}
for (int i = 25; i >= 0; i--) {
if (cnt[i] > 0) {
cnt[i]--;
ans += (char) ('a' + i);
n--;
}
}
}
return ans;
}
}