0
点赞
收藏
分享

微信扫一扫

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


题目

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 条评论