344. 反转字符串【简单】双指针秒了! 123456789101112131415161718class Solution {public: void reverseString(vector<char>& s) { int leftIndex = 0; int rightIndex = s.size() - 1; while (leftIndex < rightIndex) { // 交换字符 char tmp = s[leftIndex]; s[leftIndex] = s[rightIndex]; s[rightIndex] = tmp; // 移动指针 leftIndex++; rightIndex--; } }}; 直接用自带的 reverse 函数…… 1234567class Solution {public: void reverseString(std::vector<char>& s) { std::reverse(s.begin(), s.end()); }};