leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2785.cpp (508B)
0 class Solution {
1 static constexpr bool isvowel(char c) {
2 return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
3 };
5 public:
6 string &sortVowels(string &s) {
7 vector<char> vowels;
8 for (char c : s) {
9 if (isvowel(tolower(c))) vowels.push_back(c);
10 }
12 sort(vowels.begin(), vowels.end());
14 for (int i = 0, j = 0; i < s.size(); i++) {
15 if (isvowel(tolower(s[i]))) s[i] = vowels[j++];
16 }
18 return s;
19 }
20 };