您的位置:首页 > 其它

LeetCode 344. Reverse String 对撞指针

2017-05-02 15:11 363 查看
一、题目

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 left=0,right=s.length()-1;
while(left<right)
{
swap(s[left],s[right]);
left++;
right--;
}

return s;
}
};

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: