[LeetCode] 344.Reverse String
- 题目描述
- 解题思路
- 实验代码
题目描述
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = “hello”, return “olleh”.
解题思路
这道题很简单,也做过很多类似的练习,就是对字符串中的字符进行位置调换,当然也可以直接用string类型的reverse()函数解决问题。
实验代码
class Solution {
public:
string reverseString(string s) {
reverse(s.begin(), s.end());
return s;
}
};
本文介绍了一个简单的LeetCode题目——反转字符串的方法。通过C++代码实现,不仅展示了如何利用STL中的reverse函数轻松解决问题,还讨论了字符串中字符位置交换的基本原理。
734

被折叠的 条评论
为什么被折叠?



