Javascript solution


  • 0
    I
    let reverseStr = function(s, k) {
      if(s.length < k)
        return s.split("").reverse().join("");
      let res = "";
      for(let i = 0; i < s.length; i+=2*k) {
        res += s.split("").slice(i, i+k).reverse().join("");
        res += s.slice(i+k, i+2*k);
      }
      
     
      return res;
    };
    
    

Log in to reply
 

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