【LeetCode】344. Reverse String

作者: 033a1d1f0c58 | 来源:发表于2016-07-24 11:31 被阅读157次

C++

#include <algorithm>
class Solution {
public:
    string reverseString(string s) {
        reverse(s.begin(), s.end());
        return s;
    }
};

Java

public class Solution {
    public String reverseString(String s) {
        StringBuffer sb = new StringBuffer(s);
        return sb.reverse().toString();
    }
}

Python

class Solution(object):
    def reverseString(self, s):
        """
        :type s: str
        :rtype: str
        """
        return s[::-1]

相关文章

网友评论

    本文标题:【LeetCode】344. Reverse String

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