美文网首页
344. Reverse String

344. Reverse String

作者: SilentDawn | 来源:发表于2018-09-28 18:46 被阅读0次

    Problem

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

    Example

    Input: "hello"
    Output: "olleh"
    
    Input: "A man, a plan, a canal: Panama"
    Output: "amanaP :lanac a ,nalp a ,nam A"
    

    Code

    static int var = [](){
        std::ios::sync_with_stdio(false);
        cin.tie(NULL);
        return 0;
    }();
    class Solution {
    public:
        string reverseString(string s) {
            string res = "";
            for(int i=s.size()-1;i>=0;i--)
                res += s[i];
            return res;
        }
    };
    

    Result

    344. Reverse String.png

    相关文章

      网友评论

          本文标题:344. Reverse String

          本文链接:https://www.haomeiwen.com/subject/qoapoftx.html