[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:
bool isvowel(char c){
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') return true;
if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U') return true;
return false;
}
string reverseVowels(string s) {
int len=s.length();
int i=0,j=len-1;
while(i<j){
if(isvowel(s[i])&&isvowel(s[j])){
char temp=s[i];
s[i]=s[j];
s[j]=temp;
i++;
j--;
}
else if(isvowel(s[i])){
j--;
}
else if(isvowel(s[j])){
i++;
}
else{
i++;
j--;
}
}
return s;
}
};

【LeetCode】345. Reverse Vowels of a String 解题报告

2016-05-16 23:57:49

【LeetCode】345 Reverse Vowels of a String（java）

2016-05-04 16:15:30

345. Reverse Vowels of a String [easy] (Python)

2016-06-01 14:10:20

【LeetCode-345】 Reverse Vowels of a String(C++)

2016-05-06 11:47:01

leetcode_345 Reverse Vowels of a String

2016-05-12 21:04:34

LeetCode345—Reverse Vowels of a String

2016-04-28 15:39:00

Reverse Vowels of a String

2016年04月29日 684B 下载

[345] Reverse Vowels of a String

2016-06-25 15:27:05

LeetCode 345:Reverse Vowels of a String

2016-05-23 20:29:50

leetcode——345—— Reverse Vowels of a String

2016-04-25 10:29:04

不良信息举报

[345]Reverse Vowels of a String