LeetCode No344. Reverse String

1. 题目描述

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

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

2. 思路

直接使用标准库reverse函数

3. 代码

class Solution {
public:
    string reverseString(string s) {
        reverse(s.begin(), s.end());
        return s;
    }
};

4. 参考资料

发布了69 篇原创文章 · 获赞 15 · 访问量 9万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章