344. Reverse String

来源:互联网 发布:计算机及网络基础知识 编辑:程序博客网 时间:2024/06/18 05:19

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

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

class Solution {public:    string reverseString(string s) {        string t;        for(int i = s.length() - 1; i >= 0; --i){            t.push_back(s[i]);        }        return t;    }};
0 0
原创粉丝点击