您的位置:首页 > 编程语言 > C语言/C++

LeetCode 344. Reverse String 题解(C++)

2016-09-27 19:07 399 查看

LeetCode 344. Reverse String 题解(C++)

题目描述

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

示例

Given s = “hello”, return “olleh”.

代码

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