leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2785.cpp (508B)


      1 class Solution {
      2     static constexpr bool isvowel(char c) {
      3         return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
      4     };
      5 
      6   public:
      7     string &sortVowels(string &s) {
      8         vector<char> vowels;
      9         for (char c : s) {
     10             if (isvowel(tolower(c))) vowels.push_back(c);
     11         }
     12 
     13         sort(vowels.begin(), vowels.end());
     14 
     15         for (int i = 0, j = 0; i < s.size(); i++) {
     16             if (isvowel(tolower(s[i]))) s[i] = vowels[j++];
     17         }
     18 
     19         return s;
     20     }
     21 };