LeetCode算法提高之LeetCode刷题

【LeetCode】344. Reverse String

2016-07-24  本文已影响157人  033a1d1f0c58

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]
上一篇 下一篇

猜你喜欢

热点阅读