LeetCode题解:Reverse String

来源:互联网 发布:买情侣装的淘宝店 编辑:程序博客网 时间:2024/06/10 14:45

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

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

思路:

当然可以用双指针来做,不过最简单的还使用STL。

题解:

std::string reverseString(std::string s) {    std::string result;    std::copy(s.rbegin(), s.rend(), std::back_inserter(result));    return result;}


0 0
原创粉丝点击