344.反转字符串
小于 1 分钟
344.反转字符串
/*
* @lc app=leetcode.cn id=344 lang=typescript
*
* [344] 反转字符串
*/
// @lc code=start
/**
Do not return anything, modify s in-place instead.
*/
function reverseString(s: string[]): void {
let l = 0,
r = s.length - 1;
while (l <= r) {
// 交换
[s[l], s[r]] = [s[r], s[l]];
l++;
r--;
}
}
reverseString(["h", "e", "l", "l", "o"]);
// @lc code=end
Loading...
