Chinaunix首页 | 论坛 | 博客
  • 博客访问: 255931
  • 博文数量: 170
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1709
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-06 18:01
文章分类

全部博文(170)

文章存档

2016年(11)

2015年(130)

2014年(29)

分类: Java

2015-03-28 11:53:11

//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.

注意:使用数组保存前面的没有出现的字符,字符可能比较多 不止"a-Z"
public class LongestSubstringWithoutRepeatingCharacters {


public static void main(String[] args) {
// TODO 自动生成的方法存根


}
public int lengthOfLongestSubstring(String s) {
if(s==null)
return 0;
int max=0;
        for(int i=0;i         int j=i;
       
        int index=s.charAt(j)-' ';
        boolean exist[]=new boolean[100];
        while(!exist[index]){
        exist[index]=true;
        ++j;
        if(j>=s.length())
        break;
        index=s.charAt(j)-' ';
        }
        int len=j-i;
        max=(max>len)?max:len;
       
        }
        return max;
    }
}

阅读(1506) | 评论(0) | 转发(0) |
0

上一篇:AddTwoNumbers

下一篇:HTTP状态码

给主人留下些什么吧!~~