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

LeetCode 344. 反转字符串

 

相关文章:

  • 2021-06-13
  • 2022-12-23
  • 2021-06-14
  • 2021-09-23
  • 2021-11-12
  • 2021-12-31
猜你喜欢
  • 2022-01-22
  • 2021-10-06
  • 2022-12-23
  • 2021-11-20
  • 2021-09-22
  • 2021-08-22
  • 2021-08-14
相关资源
相似解决方案