#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
void reverseString(vector<char>& s) {
int left=0;
int right=s.size()-1;
while(right-left>=1)
{
char temp=s[right];
s[right]=s[left];
s[left]=temp;
left++;
right--;
}
}
};
int main()
{
vector<char> s={'h','e','l','l','o'};
Solution a;
a.reverseString(s);
for(auto x:s)
cout<<x;
return 0;
}
Leetcode344反转字符串(记录)C++
最新推荐文章于 2024-08-16 23:08:36 发布