C++ Simple Solution w/ Comments (Map)
\nclass Solution {\npublic:\n    string sortString(string s) {\n        // Map used for storing all chars in the input string s\n        // The map will order t
```\nclass Solution {\npublic:\n    string sortString(string s) {\n        // Map used for storing all chars in the input string s\n        // The map will order the chars for us in ascending order\n        map<char, int> letters;\n        // Store the length of s\n        int n = s.length();\n        // Add all chars to the map\n        for(int i = 0; i < n; i++)\n            letters[s[i]]++;\n        \n        // Result answer vector\n        string ans = "";\n        // Only loop through for the length of the original string\n        while(n != 0){\n            // Create an iterator for the map\n            map<char, int> :: iterator itr;\n            // Loop through the map forwards, adding each char and decrementing its count\n            for(itr = letters.begin(); itr != letters.end(); itr++){\n                if(itr->second != 0){\n                    ans += itr->first;\n                    itr->second = itr->second - 1;\n                    n--;\n                }\n            }\n            // Create a reverse iterator for the map\n            map<char, int> :: reverse_iterator it;\n            // Loop through the map backwards, adding each char and decrementing its count\n            for(it = letters.rbegin(); it != letters.rend(); it++){\n                if(it->second != 0){\n                    ans += it->first;\n                    it->second = it->second - 1;\n                    n--;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
[]