Simple JS solution without .reverse()


  • 0
    N
    /**
     * @param {string} s
     * @return {string}
     */
    var reverseString = function(s) {
        var start = 0,
            end = s.length - 1;
        
        var ret = s.split(''); // has to convert to array to reverse 
        
        while (start < end) {
            var tmp = ret[start];     
            ret[start++] = ret[end];
            ret[end--] = tmp;
        }
        
        return ret.join('');
    };
    

Log in to reply
 

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