LeetCode刷题——344. 反转字符串

Hyggelook

关注

阅读 163

2022-07-14


题目

LeetCode刷题——344. 反转字符串_对撞指针

思路

反转字符串,不能利用库函数。也可以利用对撞指针的方式,两个指针的值互换位置。

代码

class Solution(object):
def reverseString(self, s):
"""
:type s: List[str]
:rtype: None Do not return anything, modify s in-place instead.
"""
i,j = 0,len(s)-1
while i < j:
s[i],s[j] = s[j],s[i] # python中互换数组中两个元素便捷写法!!
i += 1
j -= 1
return

LeetCode刷题——344. 反转字符串_leetcode_02


精彩评论(0)

0 0 举报