您的位置:首页 > 其它

Leetcode 344. Reverse String

2016-05-19 20:50 357 查看
Write a function that takes a string as input and returns the string reversed.

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

解法一:直接用reverse函数

class Solution {
public:
string reverseString(string s) {
int len = s.length();
for(int i = 0, j = len - 1; i < j; i++, j--){
swap(s[i], s[j]);
}
return s;

}
};


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