leetcode--Longest Substring Without Repeating Characters
来源:互联网 发布:数据查询系统源代码 编辑:程序博客网 时间:2024/06/06 14:37
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) { int[] flag = new int[256];//记录当前子串中出现过的字符Arrays.fill(flag, -1);//初始值为1int start = 0;//子串起始位置int max = 0;//子串最大长度int i=0;for(i=0;i<s.length();i++){if(flag[s.charAt(i)]==-1){//如果改字符没有被记录过flag[s.charAt(i)] = i;//记录字符对应位置,标记为记录过}else{//如果出现重复字符if(max<i-start) max = i-start;//修改最大值i = flag[s.charAt(i)];//由子串中重复字符出现的位置重新计算start = i+1;//更新起始位置Arrays.fill(flag, -1);//复位}}if(max<i-start) max = i-start;//到了末尾,还要算一次return max; }}
0 0
- LeetCode: Longest Substring Without Repeating Characters
- LeetCode Longest Substring Without Repeating Characters
- LeetCode: Longest Substring Without Repeating Characters
- [Leetcode] Longest Substring Without Repeating Characters
- leetcode 23: Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- LeetCode 3 - Longest Substring Without Repeating Characters
- [LeetCode]Longest Substring Without Repeating Characters
- leetcode Longest Substring Without Repeating Characters
- 【leetcode】 Longest Substring Without Repeating Characters
- LeetCode-Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [leetcode] Longest Substring Without Repeating Characters
- LeetCode - Longest Substring Without Repeating Characters
- LeetCode 3: Longest Substring Without Repeating Characters
- leetcode-3:Longest Substring Without Repeating Characters
- leetcode之Longest Substring Without Repeating Characters
- 欢迎使用CSDN-markdown编辑器
- LeetCode_Symmetric Tree
- 01-02 数据科学家如何获取帮助
- 浅论站着说话不腰疼
- 多种方法注销linux下活动用户
- leetcode--Longest Substring Without Repeating Characters
- 「HD_ACM」A+B for Input-Output Practice (IV)
- Java设计模式之单例模式之登记式单例
- 洗草莓时不能去蒂 否则会中毒
- ubuntu14.04 安装Apache+Mysql+PHP
- 字符串反转问题
- Ubuntu下的mysql安装
- CB60-G16 IB晶振更换步骤
- 函数指针的几种用法