西宁网站建设的公司哪家好,做管理信息的网站,互动平台领手机,简约风ppt模板免费设置头尾两个指针#xff0c;依靠中间变量temp交换头尾指针所指元素#xff0c;头指针后移#xff0c;尾指针前移#xff0c;直到头尾指针重合或者头指针在尾指针后面一个元素
class Solution(object):def reverseString(self, s)::type s: List[str]:r… 设置头尾两个指针依靠中间变量temp交换头尾指针所指元素头指针后移尾指针前移直到头尾指针重合或者头指针在尾指针后面一个元素
class Solution(object):def reverseString(self, s)::type s: List[str]:rtype: None Do not return anything, modify s in-place instead.temp 0i,j 0,len(s)-1while ij:temp s[i]s[i] s[j]s[j] tempi 1j - 1if j i-1 or i j:return sclass Solution(object):def reverseString(self, s)::type s: List[str]:rtype: None Do not return anything, modify s in-place instead.return s.reverse()