注意:凡是以英文出现的,都是题目提供的,包括答案代码里的前几行。
题目:
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh"
答案:
class Solution {
public:
string reverseString(string s) {
int i = 0;
int j = s.size() - 1;
while (i < j) {
swap(s[i++], s[j--]);
}
return s;
}
};