[practice JS] just a boring solution...


  • 0
    M
    /**
     * @param {string} s
     * @return {string}
     */
    var reverseString = function(s) {
        //var sArray = s.split("");  // to char array
        //for (var i = 0, j = sArray.length - 1; i < j; ++i, --j) {  // swap sArray[i] and sArray[j]
        //    var temp = sArray[i];
        //    sArray[i] = sArray[j];
        //    sArray[j] = temp;
        //}
        //return sArray.join("");  // char array to string
        return s.split("").reverse().join("");
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.