LeetCode 344 : 翻转字符串
程序员文章站
2022-06-11 10:35:16
...
class Solution {
public:
void reverseString(vector<char>& s) {
if (s.empty() == 1)
return;
int begin = 0;
int end = s.size() - 1;
//循环, 交换
while(begin < end) {
swap(s[begin], s[end]);
begin++;
end--;
}
}
};