From cfca263b917143367385184f39be97ce0e4f8233 Mon Sep 17 00:00:00 2001 From: Yan Wen Date: Wed, 23 Jun 2021 16:26:43 +0800 Subject: [PATCH] =?UTF-8?q?update=E5=8F=8D=E8=BD=AC=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BA=86python=E6=9B=B4?= =?UTF-8?q?=E5=8A=A0=E7=AE=80=E6=B4=81=E7=9A=84=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0344.反转字符串.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/problems/0344.反转字符串.md b/problems/0344.反转字符串.md index 1b86e847..079ebb0b 100644 --- a/problems/0344.反转字符串.md +++ b/problems/0344.反转字符串.md @@ -157,7 +157,7 @@ class Solution { ``` Python: -```python3 +```python class Solution: def reverseString(self, s: List[str]) -> None: """ @@ -168,6 +168,17 @@ class Solution: s[left], s[right] = s[right], s[left] left += 1 right -= 1 + +# 下面的写法更加简洁,但是都是同样的算法 +# class Solution: +# def reverseString(self, s: List[str]) -> None: +# """ +# Do not return anything, modify s in-place instead. +# """ + # 不需要判别是偶数个还是奇数个序列,因为奇数个的时候,中间那个不需要交换就可 +# for i in range(len(s)//2): +# s[i], s[len(s)-1-i] = s[len(s)-1-i], s[i] +# return s ``` Go: