problem
solution:
class Solution { public: void reverseString(vector<char>& s) { vector<char> temp(s.size(), '0'); for(int i=s.size()-1; i>=0; i--) { temp[i] = s[s.size()-i-1]; } for(int i=0; i<s.size(); i++) { s[i] = temp[i]; } } };
solution2:
class Solution { public: void reverseString(vector<char>& s) { int left = 0, right = s.size()-1; while(left<right) { char tmp = s[left]; s[left++] = s[right]; s[right--] = tmp; } } };
参考
1. Leetcode_344_Reverse String;
完