LeetCode344

# coding:utf-8
"""
Name : NO344.py
Author  : qlb
Contect : 17801044486@163.com
Time    : 2021/2/6 23:21
Desc: 反转字符串
"""
from typing import List

# 解题思路
# 双指针 字符串首尾各一个指针 左边的指针向右滑动 右边的指针向左滑动 不断对调对应未知的元素 直到 左右两个指针相遇
class Solution:
    def reverseString(self, s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """

        i = 0
        j = len(s) - 1
        while i < j:
            tmp = s[j]
            s[j] = s[i]
            s[i] = tmp
            i += 1
            j -= 1
原文地址:https://www.cnblogs.com/cnugis/p/14383546.html