Reverse String问题及解法

来源:互联网 发布:外微分 知乎 编辑:程序博客网 时间:2024/04/27 16:59

问题描述:

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

示例:

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


过程很简单,直接看代码即可

class Solution {public:    string reverseString(string s) {        string res = "";        for(int i = s.length(); i > 0; i--)        {        res.push_back(s[i - 1]);}return res;    }};


0 0