- 这就是 std::reverse 的功能
class Solution {
public:
void reverseString(vector<char>& s) { reverse(begin(s), end(s)); }
};
- 不使用 STL 的解法如下
class Solution {
public:
void reverseString(vector<char>& s) {
int l = 0;
int r = size(s) - 1;
while (l < r) {
swap(s[l++], s[r--]);
}
}
};