遍历,交换;
class Solution {
public:
void reverseString(vector& s) {
char tmp;
int size = s.size();
for(int i = 0 ; i<size/2 ; i++)
{
tmp = s[i];
s[i] = s[size-i-1];
s[size-i-1] = tmp;
}
}
};
leetcode344:反转字符串
最新推荐文章于 2021-09-28 16:13:44 发布
遍历,交换;
class Solution {
public:
void reverseString(vector& s) {
char tmp;
int size = s.size();
for(int i = 0 ; i<size/2 ; i++)
{
tmp = s[i];
s[i] = s[size-i-1];
s[size-i-1] = tmp;
}
}
};