class Solution(object):
def reverseString(self, s):
"""
:type s: List[str]
:rtype: None Do not return anything, modify s in-place instead.
"""
'''
all_data=len(s)
for i in range(all_data//2):
s[i],s[all_data-1-i]=s[all_data-1-i],s[i]
'''
f_index=0
l_index=len(s)-1
all_num=l_index+1
while all_num>1:
s[f_index],s[l_index]=s[l_index],s[f_index]
f_index+=1
l_index-=1
all_num-=2
双指针-344-反转字符串
最新推荐文章于 2024-11-01 15:19:21 发布