class Solution {
public:
string reverseString(string s) {
int i = 0, j = s.size() - 1;
while(i < j){
swap(s[i++], s[j--]);
}
return s;
}
};
反正思路都一样~两头换一换
class Solution {
public:
string reverseString(string s) {
char temp;
int length=s.length();
for(int i = 0; i < length/2; i++){
temp = s[length-1-i];
s[length-1-i] = s[i];
s[i] = temp;
}
return s;
}
};
1、void swap (T& a, T& b):Exchanges the values of a and b.