DEV Community

Karleb
Karleb

Posted on

#344. Reverse String

https://leetcode.com/problems/reverse-string/description/?envType=daily-question&envId=2024-06-02


/**
 * @param {character[]} s
 * @return {void} Do not return anything, modify s in-place instead.
 */
var reverseString = function(s) {
    let start  = 0, end = s.length - 1

    while(start < end) {
        // let ch = s[start]
        // s[start] = s[end]
        // s[end] = ch

        [s[start], s[end]] = [s[end], s[start]]

        start++
        end--
    }
};

Enter fullscreen mode Exit fullscreen mode

Top comments (0)