# 【 关关的刷题日记50】 Leetcode 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".

Note: The vowels does not include the letter "y"..

## 思路

```class Solution {
public:
string reverseVowels(string s) {
if(s.empty() || s.size()==1)
return s;
for(int i=0, j=s.size()-1; i<j;)
{
while(!(tolower(s[i])=='a' || tolower(s[i])=='e' || tolower(s[i])=='i' || tolower(s[i])=='o' || tolower(s[i])=='u'))
i++;
while(!(tolower(s[j])=='a' || tolower(s[j])=='e' || tolower(s[j])=='i' || tolower(s[j])=='o' || tolower(s[j])=='u'))
j--;
if(i<j)
{
swap(s[i],s[j]);
i++;
j--;
}
}
return s;
}
};```

0 条评论

## 相关文章

37180

36460

### 2729: [HNOI2012]排队

2729: [HNOI2012]排队 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 957  Solved:...

30250

37160

29470

35560

### 3. call PRXSUBSTR () | 庖丁解牛切割数据！

【SAS Says·扩展篇】庖丁解牛割数据！ | 3. call PRXSUBSTR () 0. 前集回顾 1. 新的问题 2. 初识 PRXSUBSTR() ...

36250

35180

40250

29050