首页 > 其他 > 详细

Longest Substring Without Repeating Characters

时间:2014-02-22 22:00:11      阅读:422      评论:0      收藏:0      [点我收藏+]

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.

bubuko.com,布布扣
 1 public class Solution {
 2     public int lengthOfLongestSubstring(String s) {
 3         int len = s.length();
 4         if(len<=0) return 0;
 5         int c[] = new int [26];
 6         reset(c);
 7         int count=0;
 8         int max = 0;
 9         for(int i=0;i<len;i++,count++){
10             if(c[s.charAt(i)-‘a‘]!=-1){
11                 i = c[s.charAt(i)-‘a‘]+1;
12                 reset(c);
13                 max = Math.max(max,count);
14                 count = 0;
15             }
16             c[s.charAt(i)-‘a‘] = i;
17         }
18         max = Math.max(max,count);
19         return max;
20        
21     }
22     public void reset (int []c){
23         for(int i=0;i<26;i++){
24             c[i]=-1;
25         }
26     }
27 }
View Code

Longest Substring Without Repeating Characters

原文:http://www.cnblogs.com/krunning/p/3560699.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!