【leetcode】Longest Substring Without Repeating Characters
2015-03-16 22:29
302 查看
问题描述:
问题分析:见博客:http://blog.csdn.net/pickless/article/details/9018575
代码:
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.
问题分析:见博客:http://blog.csdn.net/pickless/article/details/9018575
代码:
public int lengthOfLongestSubstring(String s) { if(s==null || s.isEmpty()==true) return 0; Map<Character,Integer> map = new HashMap<Character,Integer>(); int start=0; int end=1; int max=1; map.put(s.charAt(start), 0); while(end<s.length()){ //当前元素没有出现过 if(!map.containsKey(s.charAt(end))){ //先给map中填充 map.put(s.charAt(end), end); max=Math.max(max, end-start+1); }else{ //当前元素出现了 if(map.get(s.charAt(end))>=start){ start=map.get(s.charAt(end))+1; } map.put(s.charAt(end),end); max=Math.max(max, end-start+1); } end++; } return max; }
相关文章推荐
- leetcode 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 求链表中无重复字符的最大字串长度(AC)
- leetcode Longest Substring Without Repeating Characters
- LeetCode-Longest Substring Without Repeating Characters
- [leetcode]Longest Substring Without Repeating Characters @ Python
- LeetCode 003 Longest Substring Without Repeating Characters
- 《leetCode》:Longest Substring Without Repeating Characters
- LeetCode Longest Substring Without Repeating Characters 最长不重复子串查找
- [leetcode Q3] —— Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- leetcode 3 Longest Substring Without Repeating Characters
- [LeetCode]Longest Substring Without Repeating Characters@python
- Longest Substring Without Repeating Characters-----LeetCode
- Leetcode-Longest Substring Without Repeating Characters
- 【leetcode】 Longest Substring Without Repeating Characters
- LeetCode:Longest Substring Without Repeating Characters