您的位置:首页 > 其它

LeetCode 345 Reverse Vowels of a String

2017-06-10 14:31 316 查看

LeetCode 345 Reverse Vowels of a String

//vowels : a e i o u

#include <string>

using namespace std;

class Solution {

public:
bool isVowel(char s){
if (s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u' || s == 'A' || s == 'E' || s == 'I' || s == 'O' || s == 'U')
return true;
else
return false;

}
string reverseVowels(string s) {
int start = 0;
int end = s.length() - 1;
while (start < end)
{
if (isVowel(s[start]) && isVowel(s[end]))
{
swap(s[start], s[end]);
start++;
end--;
}
else if (!isVowel(s[start]) && isVowel(s[end]))
start ++;
else if (!isVowel(s[end]) && isVowel(s[start]))
end --;
else
{
start++;
end--;
}
}
return s;

}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode