Reverse-String

第80天。

今天的题目是Reverse String:

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = “hello”, return “olleh”.

水的不能再水的题目.

1
2
3
4
5
6
7
string reverseString(string s) {
int i = 0,j = s.size() - 1;
while(i < j) {
swap(s[i++],s[j--]);
}
return s;
}

如果用python话:

1
2
3
4
5
6
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
return s[::-1]