344.反转字符串
题目链接
static const auto io_speed_up = []()
{
ios::sync_with_stdio(false);
cin.tie(0);
return 0;
}();
class Solution {
public:
void reverseString(vector<char>& s) {
int i = 0,j = s.size()-1;
while(i<j)swap(s[i++],s[j--]);
}
};
345.反转字符串中的元音字母
题目链接
static const auto io_speed_up = []()
{
ios::sync_with_stdio(false);
cin.tie(0);
return 0;
}();
class Solution {
public:
bool isvow(char p){
p = tolower(p);
if(p=='a'||p=='e'||p=='i'||p=='o'||p=='u')return 1;
return 0;
}
string reverseVowels(string s) {
int i = 0, j = s.size()-1;
while(i<j){
if(!isvow(s[i]))i++;
else if(!isvow(s[j]))j--;
else swap(s[i++],s[j--]);
}
return s;
}
};