345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Given s = "hello", return "holle".
Example 2:
Given s = "leetcode", return "leotcede".
class Solution { public: string reverseVowels(string s) { if (s.size() == 0) return s; int start = 0; int end = s.size() - 1; while (start < end) { while (!isVowel(s[start])) { ++start; } while (!isVowel(s[end])) { --end; } if(start<end) { char tmp = s[start]; s[start] = s[end]; s[end] = tmp; start++; end--; } } return s; } bool isVowel(char ch) { vector<char> cvec{ 'a','e','i','o','u' ,'A','E','I','O','U'}; if (find(cvec.begin(), cvec.end(), ch) == cvec.end()) return false; return true; } };