题目描述:
代码实现:
方法一:
- 函数法
/**
* @param {character[]} s
* @return {void} Do not return anything, modify s in-place instead.
*/
var reverseString = function(s) {
return s.reverse()
};
方法二:
- es6解构赋值
/**
* @param {character[]} s
* @return {void} Do not return anything, modify s in-place instead.
*/
var reverseString = function(s) {
for (var i = 0; i < s.length / 2; i++ ) {
[s[i], s[s.length - 1 - i]] = [s[s.length - 1 - i], s[i]]
}
};