码迷,mamicode.com
首页 > 其他好文 > 详细

Longest Substring Without Repeat Characters

时间:2015-11-22 00:19:16      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

 1 var lengthOfLongestSubstring = function(s) {
 2     if (s === ‘‘) {
 3         return 0;
 4     }
 5 
 6     var lenMax = 1,
 7         lenCurr = 1,
 8         i, repeat;
 9 
10     for (i = 1; i < s.length; i++) {
11         repeat = s.substr(i - lenCurr, lenCurr).indexOf(s.substr(i, 1));
12 
13         if (repeat == -1) {
14             lenCurr++;
15         } else {
16             lenCurr -= repeat;
17         }
18 
19         if (lenCurr > lenMax) {
20             lenMax = lenCurr;
21         }
22     }
23 
24     return lenMax;
25 };

 

Longest Substring Without Repeat Characters

标签:

原文地址:http://www.cnblogs.com/huoteng/p/4985089.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!