【字符串】 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 };

猜你喜欢

转载自www.cnblogs.com/ocpc/p/12823041.html