Reverse String

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

Example: Given s = "hello", return "olleh".

URL: https://leetcode.com/problems/reverse-string/

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

        current_str = [char for char in s]

        i = 0
        j = len(s) - 1

        while i < j:
            temp = current_str[i]
            current_str[i] = current_str[j]
            current_str[j] = temp
            j -= 1
            i += 1

        return "".join(current_str)

results matching ""

    No results matching ""