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