One Line JavaScript Solution

  • 0

    One line solution implemented in JavaScript.
    Pretty clear and concise, but the solution is not fullfilled the requirement of the space complexity(O(1));

    var reverseWords = function(str) {
        return str.split(" ").filter(function(ele){return ele.length>0}).reverse().join(" ");

Log in to reply

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