题解 | #字符串反转#
字符串反转
https://www.nowcoder.com/practice/e45e078701ab4e4cb49393ae30f1bb04
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void (async function () { // Write your code here // 思路 遍历一半就可以了,或者用位移的方式应该也可以解决。 // 但可惜不是数组,字符串的对换赋值不好使,我就转为数组再转回字符串。 let str = (await readline()).split(""); var len = str.length; for (var i = 0; i < len / 2; i++) { [str[i], str[len - i - 1]] = [str[len - i - 1], str[i]]; } console.log(str.join("")); })();