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

Commitf6b6adb

Browse files
Merge pull requestyoungyangyang04#435 from borninfreedom/master
update反转字符串,添加了python更加简洁的写法
2 parents500ed63 +cfca263 commitf6b6adb

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
@@ -155,7 +155,7 @@ class Solution {
155155
```
156156

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

171182
Go:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp