Increasing Decreasing String LeetCode solution in C++

1
class Solution {
2
public:
3
string sortString(string s) {
4
int count[26] = {0};
5
for (int i = 0; i < s.size(); i++) {
6
char ch = s[i];
7
count[ch - 'a']++;
8
}
9
string res;
10
while (res.size() != s.size()) {
11
for (int i = 0; i < 26; i++) {
12
if (count[i] > 0) {
13
char ch = i + 'a';
14
res += ch;
15
count[i]--;
16
}
17
}
18
for (int i = 25; i >= 0; i--) {
19
if (count[i] > 0) {
20
char ch = i + 'a';
21
res += ch;
22
count[i]--;
23
}
24
}
25
}
26
return res;
27
}
28
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0