Напишите функцию, которая переворачивает строку. Входная строка задана в виде массива символов s.

from typing import List

class Solution:
    def reverseString(self, s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
        left, right = 0, len(s) - 1
        while left < right:
            # Swap characters at left and right pointers
            s[left], s[right] = s[right], s[left]
            # Move pointers towards the center
            left += 1
            right -= 1
            
solution = Solution()
s = ["h", "e", "l", "l", "o"]
solution.reverseString(s)
print(s)  # Output: ["o", "l", "l", "e", "h"]
def func(lst):
    lst.reverse()
    return lst

Last updated

Was this helpful?