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) {
int size = s.size();
int temp;
//The most important is: 注意NULL结尾的字符串 for(int i=0; i<size/2; i++){
temp = s[i];
s[i] = s[size-1-i];
s[size-1-i] = temp;
}
return s;
}
};
本文介绍如何使用C++编程语言实现一个将输入字符串反转的功能。通过定义一个类和相应的成员函数,我们实现了字符串反转的过程,并通过示例演示了其使用方法。

2690

被折叠的 条评论
为什么被折叠?



