[LeetCode] 344.Reverse String

来源:互联网 发布:幼儿教育发展前景知乎 编辑:程序博客网 时间:2024/06/05 02:07

[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;    }};
原创粉丝点击