Sharing JS script, beats 100.00% of javascript submissions


  • 0
    M
    /**
     * @param {string} str
     * @returns {string}
     */
    var reverseWords = function(str) {
        var b = str.split(' ');
        var s = '';
        for (i=b.length-1;i>=0;i--)
        {
            if (b[i]!=='')s+=b[i]+' ';
        }
        return s.trimRight();
    };

Log in to reply
 

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