Longest Substring Without Repeating Characters
来源:互联网 发布:dota2饰品 知乎 编辑:程序博客网 时间:2024/04/29 00:09
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.
public class Solution { public int lengthOfLongestSubstring(String s) { if(s==null||s.length()==0) return 0; if(s.length()==1) return 1; char[] c = s.toCharArray(); int longest = 0,index = 0,now = 0; int [] map = new int[26]; Arrays.fill(map,-1); //下标有可能会出现 0!! 所以不可以用0!! for(int i=0;i<c.length;i++){ if(map[c[i]-'a']==-1||map[c[i]-'a']<index){ //后者剔除一些错误的存留数据!! now++; map[c[i]-'a']=i; if(now>longest){ longest = now; } }else{ now-=(map[c[i]-'a']-index); index = map[c[i]-'a']+1; map[c[i]-'a'] = i; } } return longest; }}
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- IOS开发之Block编程
- 如何构建下拉滑动式响应导航菜单
- Oracle VM 安装GHOST 镜像
- CentOS系统安装JDK
- javascript深入理解js闭包
- Longest Substring Without Repeating Characters
- 排序2--选择(蛮力法)
- 动画
- finalize
- 在64-bit机器上运行32-bit的应用程序,需要安装ia32-libs库
- 实例化Spring Ioc容器,生成SequenceGenerator
- Java程序员推荐书目
- sql总结
- ORACLE10G手工创建数据库非ASM