My Javascript Solution


  • 0
    M
    /**
     * @param {string} str
     * @returns {string}
     */
    var reverseWords = function(str) {
        str = str.trim().split(" ");
        var new_arr = [];
        for(var i = str.length - 1; i >= 0; i--) {
            if(str[i])
                new_arr.push(str[i])
        }
        
        return new_arr.join(" ");
    };
    

Log in to reply
 

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