Longest Substring Without Repeating Characters
<html> <head> <meta http-equiv="charset" content="utf-8"></head> <body> <script> // 解题思路: // 设置两个指针,start和end,end一直向后走,如果遇到前面出现过的字符串,start向前走一步 var s = ‘asdasdas‘; var lengthOfLongestSubstring = function(s) { var length = 0;//lengthOfLongestSubstring var len = s.length; var start=0; var end=0; var tempArr = []; while(end !== len) { if(tempArr.indexOf(s[end])===-1) { tempArr.push(s[end]); if(tempArr.length > length) length = tempArr.length; end++; } else { tempArr.shift(); start++; } } return length; }; alert(lengthOfLongestSubstring(s)); </script></body> </htm
时间: 2024-12-16 22:47:31