class Solution {
public:
string sortString(string s)
{
string res;
int temp[26] = {0};
for (int i = 0; i < s.length(); i++)
{
temp[s[i] - 'a']++;
}
int len = s.size();
while (len)
{
for (int i = 0; i < 26; i++)
{
if (temp[i] > 0)
{
res += 'a' + i;
temp[i]--;
len--;
}
}
for (int i = 25; i >= 0; i--)
{
if (temp[i] > 0)
{
res += 'a' + i;
temp[i]--;
len--;
}
}
}
return res;
}
};
不懂为什么这个题目的通过率那么高orz,可能是我太菜了吧