【字符串】 344. 反转字符串

题目:

 

 

解答:

 1 class Solution {
 2 public:
 3     void reverseString(vector<char>& s) 
 4     {
 5         if (s.size() <= 1)
 6         {
 7             return;
 8         }
 9 
10         int beg = 0;
11         int end = s.size() - 1;
12 
13         while (beg < end)
14         {
15             char tmp = s[beg];
16             s[beg] = s[end];
17             s[end] = tmp;
18             beg++;
19             end--;
20         }
21     }
22 };

 

posted @ 2020-05-03 19:21  梦醒潇湘  阅读(207)  评论(0)    收藏  举报