一:题目
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 ReverseString;
int i;
for(i=s.length()-1;i>=0;i--)
ReverseString+=s[i];
return ReverseString;
}
};