Longest Substring Without Repeating Characters
来源:互联网 发布:会计软件单机版 编辑:程序博客网 时间:2024/06/08 07:52
原理: 历遍字符串,查看当前字符是否出现过,当出现过的时候,子串开始位置+1,否则更新locs数组中的地址值为当前位置。
public class Solution {
public int lengthOfLongestSubstring(String s) {int[] locs = new int[256];
int index = 0;
int idx = -1;
int max =0;
long pretime;
long endtime;
for(int i = 0; i < locs.length; i++){
locs[i] = -1;
}
for( index = 0; index < s.length(); index++){
if(locs[(int)s.charAt(index)] > idx){ // 说明这个字符出现过
idx = locs[s.charAt(index)];
}
if(index - idx > max){
max = index - idx;
}
locs[s.charAt(index)] = index;
}
return max;
}
}
0 0
- 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
- Red and Black(BFS or DFS)
- 神经网络总结(初稿)
- 算法与数据结构八日谈之六——数据结构专题(uncompleted)
- LeetCode 219: Contains Duplicate II
- 黑马程序员——12_File_deleteOnExit()试验
- Longest Substring Without Repeating Characters
- IOS菜鸟的所感所思(十六)—— 立体式的切换视图
- C语言-解析命令行参数
- 二叉树相关算法总结
- K650c + Ubuntu15.04双显卡切换
- PHP 类的一些知识点
- java 获取时间
- 应用select 函数控制多线程中子线程结束方法
- HBase的LSM树