JavaScript array solution


  • 1
    K

    /**

    • @param {string} s
    • @return {string}
      */
      var reverseString = function(s) {
      var arr = s.split("");
      var newArr = arr.reverse();
      var newS = newArr.join("");
      return newS;
      };

  • 2

    It could be more shorter if you written like this :)

    var reverseString = function(s) {
        return s.split("").reverse().join("");
    };

Log in to reply
 

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