您的位置:首页 > 其它

15算法课程 344. Reverse String

2017-12-22 23:29 344 查看


Write a function that takes a string as input and returns the string reversed.

Example:

Given s = "hello", return "olleh".

solution:

字符串反转

code:

class Solution {
public:
string reverseString(string s) {
int left=0, right=s.length()-1;
while(left<right)
{
swap(s[left], s[right]);
left++, right--;
}
return s;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: