【LeetCode】344. Reverse String
题目:
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) { string str = s; if (str == "") return str; if (str.size() == 1) return str; for (int i = 0, j = str.size()-1; i < j;){ char tmp = str[i]; str[i] = str[j]; str[j] = tmp; i++; j--; } return str; } };