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 j = s.size()-1, i = 0;
while(i < j)
{
swap(s[i++], s[j--]);
}
return s;
}
};
本文介绍了一个简单的C++函数,该函数接收一个字符串作为输入,并返回其反转后的字符串。例如,输入hello,则返回olleh。通过交换字符串两端的字符来实现字符串的反转。
710

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



