Loading

LeetCode 344. 反转字符串

 

思路

方法:首尾双指针

 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 };

 

posted @ 2021-03-06 20:51  拾月凄辰  阅读(31)  评论(0编辑  收藏  举报