You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * @param {character[]} s * @return {void} Do not return anything, modify s in-place instead. */// 双指针// var reverseString = function(s) {// const n = s.length;// for (let left = 0, right = n - 1; left < right; left++, right--) {// [s[left], s[right]] = [s[right], s[left]]// }// };varreverseString=function(s){letleft=0,right=s.length-1while(left<right){[s[left],s[right]]=[s[right],s[left]]left++right--}}
The text was updated successfully, but these errors were encountered:
344. 反转字符串
Description
Difficulty: 简单
Related Topics: 递归, 双指针, 字符串
编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组
s
的形式给出。不要给另外的数组分配额外的空间,你必须修改输入数组、使用 O(1) 的额外空间解决这一问题。
示例 1:
示例 2:
提示:
s[i]
都是 码表中的可打印字符Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: