[Leetcode344]反转字符串

编写一个函数,其作用是将输入的字符串反转过来。

 这道题比较简单。

python:

class Solution(object):
    def reverseString(self, s):
        """
        :type s: str
        :rtype: str
        """

        return s[::-1]

C++: 

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

猜你喜欢

转载自blog.csdn.net/qq_40501689/article/details/82959959
今日推荐