Reverse-String

Dec 16, 2017

第80天。

今天的题目是Reverse String:

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

Example: Given s = “hello”, return “olleh”.

水的不能再水的题目.

string reverseString(string s) {
    int i = 0,j = s.size() - 1;
    while(i < j) {
        swap(s[i++],s[j--]);
    }
    return s;
}

如果用python话:

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

Remove-Element

Reverse-Words-in-a-String-III

comments powered by Disqus