leetcode 刷题之: reverse string

来源:互联网 发布:淘宝商品软文范例 编辑:程序博客网 时间:2024/06/05 00:17

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

Subscribe to see which companies asked this question


class Solution {
public:
    string reverseString(string s) {
        int len = s.length();
        string r;
        for(int i=0; i<len; i++)
        {
            //r.push_back(s[len-1-i]);     //+ and push_back() function are both OK
            r += s[len-1-i];
            //r.append(s[len-1-i]);
        }
        return r;
    }
};

0 0
原创粉丝点击