【LeetCode】3.Longest Substring Without Repeating Characters 最长无重复子串
题目:
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
思路:
初始字符上一次出现的位置-1,初始子串开始位置-1。对字符串中每个字符元素遍历,判断更新子串的开始位置及最大长度,循环结束后 返回最大长度max.
public class Solution {
public int lengthOfLongestSubstring(String s) {
int[] local=new int[128];
int index=-1;
int max=0;
for(int a=0;a<local.length;a++){
local[a]=-1;
}
for(int i=0;i<s.length();i++){
if(local[(int)s.charAt(i)]>index){
index=local[(int)s.charAt(i)];
}
if(i-index>max){
max=i-index;
}
local[(int)s.charAt(i)]=i;
}
return max;
}
}
【LeetCode】3.Longest Substring Without Repeating Characters 最长无重复子串的更多相关文章
- [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- leetcode 3 Longest Substring Without Repeating Characters最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- [LeetCode] Longest Substring Without Repeating Characters最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串 C++实现java实现
最长无重复字符的子串 Given a string, find the length of the longest substring without repeating characters. Ex ...
- 【LeetCode每天一题】Longest Substring Without Repeating Characters(最长无重复的字串)
Given a string, find the length of the longest substring without repeating characters. Example 1: ...
- LeetCode Longest Substring Without Repeating Characters 最长不重复子串
题意:给一字符串,求一个子串的长度,该子串满足所有字符都不重复.字符可能包含标点之类的,不仅仅是字母.按ASCII码算,就有2^8=128个. 思路:从左到右扫每个字符,判断该字符距离上一次出现的距离 ...
- 003 Longest Substring Without Repeating Characters 最长不重复子串
Given a string, find the length of the longest substring without repeating characters.Examples:Given ...
随机推荐
- 剑指offer系列26--正则表达式匹配
[题目]请实现一个函数用来匹配包括’.’和’*‘的正则表达式.模式中的字符’.’表示任意一个字符,而’‘表示它前面的字符可以出现任意次(包含0次). 在本题中,匹配是指字符串的所有字符匹配整个模式.例 ...
- Redis资料汇总专题
1.Redis是什么? 十五分钟介绍 Redis数据结构 Redis系统性介绍 一个很棒的Redis介绍PPT 强烈推荐!非同一般的Redis介绍 Redis之七种武器 锋利的Redis redis ...
- IntelliJ IDEA修改Output输出缓存区大小【应对:too much output to process】
IntelliJ IDEA默认的Output输出缓存区大小只有1024KB,超过大小限制的就会被清除,而且还会显示[too much output to process],可通过如下配置界面进行修改O ...
- android学习笔记七——控件(DatePicker、TimePicker、ProgressBar)
DatePicker.TimePicker ==> DatePicker,用于选择日期 TimePicker,用于选择时间 两者均派生与FrameLayout,两者在FrameLayout的基础 ...
- J2EE学习中一些值得研究的开源项(转)
这篇文章写在我研究J2SE.J2EE近三年后.前3年我研究了J2SE的Swing.Applet.Net.RMI.Collections. IO.JNI……研究了J2EE的JDBC.Sevlet.JSP ...
- JavaScript如何获得昨天明天等日期
<script type="text/javascript"> function GetDateStr(AddDayCount) { var dd = new Date ...
- C4.5决策树算法概念学习
数据挖掘一般是指从大量的数据中自动搜索隐藏于其中的有着特殊关系性的信息的过程. •分类和聚类 •分类(Classification)就是按照某种标准给对象贴标签,再根据标签来区分归类,类别数不变. • ...
- Form_Form Builder编译fmb/library/menu方式总结(汇总)
2014-12-27 Created By BaoXinjian
- PLSQL_PLSQL读和写CSV文件方式(案例)
2012-01-06 Created By BaoXinjin
- PLSQL_Oracle Logon Trigger的建立
20150609 Created By BaoXinjian