标签:
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
[JS做LeetCode] Longest Substring Without Repeating Characters
标签:
原文地址:http://www.cnblogs.com/oadaM92/p/4355851.html