zl程序教程

您现在的位置是:首页 >  其他

当前栏目

LeetCode 344. 反转字符串

LeetCode 字符串 反转
2023-09-11 14:19:00 时间

 

思路

方法:首尾双指针

 1 class Solution {
 2 public:
 3     void reverseString(vector<char>& s) {
 4         int i = 0, j = s.size()-1;
 5         while(i < j) {
 6             swap(s[i], s[j]);
 7             ++i;
 8             --j;
 9         }
10     }
11 };