forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0345.cpp
More file actions
33 lines (32 loc) · 698 Bytes
/
0345.cpp
File metadata and controls
33 lines (32 loc) · 698 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
#include <string>
#include <iostream>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
string reverseVowels(string s)
{
string vowels = "aeiouAEIOU";
int l = 0;
int r = s.size() - 1;
while (l < r)
{
l = s.find_first_of(vowels, l);
r = s.find_last_of(vowels, r);
if (l < r)
{
char tmp = s[l];
s[l++] = s[r];
s[r--] = tmp;
}
}
return s;
}
};
int main()
{
string s = "hello";
cout << Solution().reverseVowels(s) << endl;
return 0;
}