第80天。
今天的题目是Reverse String:
Write a function that takes a string as input and returns the string reversed.
Example: Given s = “hello”, return “olleh”.
水的不能再水的题目.
1string reverseString(string s) {2 int i = 0,j = s.size() - 1;3 while(i < j) {4 swap(s[i++],s[j--]);5 }6 return s;7}
如果用python
话:
1def reverseString(self, s):2 """3 :type s: str4 :rtype: str5 """6 return s[::-1]