LeetCode 344:Reverse String (c++)
2017-06-21 09:02
316 查看
一:题目
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) {
//反转字符串,从结束位置开始遍历字符串,并将其赋值给另一个字符串
string ReverseString;
int i;
for(i=s.length()-1;i>=0;i--)
ReverseString+=s[i];
return ReverseString;
}
};
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) {
//反转字符串,从结束位置开始遍历字符串,并将其赋值给另一个字符串
string ReverseString;
int i;
for(i=s.length()-1;i>=0;i--)
ReverseString+=s[i];
return ReverseString;
}
};
相关文章推荐
- [LeetCode-344]Reverse String(c++)
- LeetCode 344. Reverse String 题解(C++)
- leetcode_c++: Reverse String(344)
- leetcode_344_ Reverse String(C++)(easy)
- 【LeetCode-344】 Reverse String(C++)
- LeetCode 第 344 题(Reverse String)
- LeetCode-344.Reverse String
- LeetCode *** 344. Reverse String
- LeetCode344—Reverse String
- Leetcode:344. Reverse String
- 【LeetCode】344. Reverse String 解题报告
- Leetcode Reverse String 344
- LeetCode笔记:344. Reverse String
- leetcode 344 Reverse String (in java)
- [leetcode 344]Reverse String
- leetcode 344: Reverse String (c#版)
- Leetcode 344 Reverse String 字符串处理
- Leetcode 344 Reverse String
- LeetCode 344. Reverse String
- <LeetCode>344. Reverse String