乐趣区

关于golang:Leetcode专题字符串344反转字符串

力扣链接:
https://leetcode-cn.com/probl…
解题思路:

  1. 翻转字符串这道题比较简单,应用两个指针,而后从首位开始遍历,替换首尾地位,循环直到首尾相遇
func reverseString(s []byte)  {n := len(s)
    low, high := 0, n-1
    for low <= high {s[low], s[high] = s[high], s[low]
        low++
        high--
    }
}
退出移动版