Wednesday, June 15, 2022

lengthOfLongestSubstring

 /**

 * @param {string} s

 * @return {number}

 */

var lengthOfLongestSubstring = function(s) {

  var arr = [], i_count = 0, j_count = 0, max_count = 0, _s = ""

  for(var i = 0; i < s.length; i++){

    var c = s[i]

    var k = _s.indexOf(c)

    if(k > -1){

      _s = _s.substring(k+1)

    }

    _s += c

    if(_s.length > max_count){

      max_count = _s.length

    }

  }

  return max_count

};


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Generate a catchy title for a collection of newfangled music by making it your own

Write a newfangled code fragment at an earlier stage to use it. Then call another method and make sure their input is the correct one. The s...