One liner javascript solution.


  • 0
    I
    /**
     * @param {string} str
     * @returns {string}
     */
    var reverseWords = function(str) {
        return str.trim().split(/\s+/).reverse().join(" ")
    };
    

    Only beats 20%, could you provide a better short solution?


Log in to reply
 

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