题目描述:
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 i=0;
int j=s.size()-1;
while(i<=j)
{
char temp=s[i];
s[i]=s[j];
s[j]=temp;
i++;
j--;
}
return s;
}
};
本文介绍了一个使用C++编写的字符串反转函数。该函数接受一个字符串作为输入,并返回其反转后的结果。通过两个指针从两端开始交换字符,直至中间位置,实现了字符串的高效反转。
1415

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



