Skip to content

Latest commit

 

History

History
10 lines (9 loc) · 331 Bytes

反转字符串.md

File metadata and controls

10 lines (9 loc) · 331 Bytes
function reverseString(s) {
  // 利用双指针技巧 反转的对应关系为 s[i] 与 s[s.length - 1 - i] 交换
  for (let left = 0, right = s.length - 1; left < right; left++, right--) {
    [s[left], s[right]] = [s[right], s[left]];
  }
}