-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode-345.cpp
More file actions
34 lines (31 loc) · 893 Bytes
/
LeetCode-345.cpp
File metadata and controls
34 lines (31 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*************************************************************************
> File Name: LeetCode-345.cpp
> Author: ltw
> Mail: 3245849061@qq.com
> Created Time: Thu 21 May 2020 07:17:06 PM CST
************************************************************************/
#include <iostream>
using namespace std;
class Solution {
public:
bool is_valid(char ch) {
if (ch < 97) ch += 32;
switch (ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u': return true;
}
return false;
}
string reverseVowels(string s) {
for (int i = 0, j = s.size() - 1; i < j; i++, j--) {
while (i < j && !is_valid(s[i])) ++i;
while (i < j && !is_valid(s[j])) --j;
if (i >= j) break;
swap(s[i], s[j]);
}
return s;
}
};