leetcode

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

0345.cpp (520B)


0 class Solution {
1 bool is_vowel(char c) {
2 c = tolower(c);
3 return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
4 }
6 public:
7 string reverseVowels(string s) {
8 int i = 0, j = size(s) - 1;
9 while (i < j) {
10 while (i < j && !is_vowel(s[i]))
11 i++;
12 while (i < j && !is_vowel(s[j]))
13 j--;
14 if (i >= j) break;
15 swap(s[i], s[j]);
16 i++;
17 j--;
18 }
19 return s;
20 }
21 };