Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcfca263

Browse files
author
Yan Wen
committed
update反转字符串,添加了python更加简洁的写法
1 parent7d3b01b commitcfca263

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

‎problems/0344.反转字符串.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class Solution {
157157
```
158158

159159
Python:
160-
```python3
160+
```python
161161
classSolution:
162162
defreverseString(self,s: List[str]) ->None:
163163
"""
@@ -168,6 +168,17 @@ class Solution:
168168
s[left], s[right]= s[right], s[left]
169169
left+=1
170170
right-=1
171+
172+
# 下面的写法更加简洁,但是都是同样的算法
173+
# class Solution:
174+
# def reverseString(self, s: List[str]) -> None:
175+
# """
176+
# Do not return anything, modify s in-place instead.
177+
# """
178+
# 不需要判别是偶数个还是奇数个序列,因为奇数个的时候,中间那个不需要交换就可
179+
# for i in range(len(s)//2):
180+
# s[i], s[len(s)-1-i] = s[len(s)-1-i], s[i]
181+
# return s
171182
```
172183

173184
Go:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp