美文网首页
2019-05-19LeetCode344. 反转字符串

2019-05-19LeetCode344. 反转字符串

作者: mztkenan | 来源:发表于2019-05-19 17:26 被阅读0次

双指针,5min

class Solution:
    def reverseString(self, s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
        low,high=0,len(s)-1
        mid=(low+high)//2
        while(low<=mid):
            tmp=s[low]
            s[low]=s[high]
            s[high]=tmp
            low+=1
            high-=1

相关文章

网友评论

      本文标题:2019-05-19LeetCode344. 反转字符串

      本文链接:https://www.haomeiwen.com/subject/esuqzqtx.html