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;
}
};

本文介绍了使用C++实现字符串反转及元音字母反转的方法,通过具体代码示例展示了如何高效地进行字符串处理,适用于需要对字符串进行特定操作的场景。
315

被折叠的 条评论
为什么被折叠?



