题目:
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
思路:首尾字符交换
c++代码:
1 class Solution { 2 public: 3 string reverseString(string s) { 4 int len = s.size(); 5 for (int i = 0; i < len/2; i++) { 6 char t = s[i]; 7 s[i] = s[len-i-1]; 8 s[len-i-1] = t; 9 } 10 return s; 11 } 12 };