reverse_string

  • 2022-12-14
  • 浏览 (516)

reverse_string.py 源码

from typing import List


# 反转字符串

class Solution:

    def reverseString_1(self, s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
        s.reverse()

    def reverseString_2(self, s: List[str]) -> None:
        i, j = 0, len(s) - 1
        while i < j:
            s[i], s[j] = s[j], s[i]
            i, j = i + 1, j - 1

你可能感兴趣的文章

first_unique_char

implement_strstr

is_palindrome

0  赞