1.题目
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = “hello”, return “olleh”.
翻转字符串,很直白的题目
2.代码
python
宝宝终于会偷懒了,深感欣慰啊
def reverseString(self, s):
return s[::-1]
c++
string reverseString(string s) {
int i = 0;
int j = s.length() - 1;
while (i < j) {
char temp = s[i];
s[i] = s[j];
s[j] = temp;
++i;
--j;
}
return s;
}