标签:style color io ar java for sp div art
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 result=0; Map<Character,Integer> map=new HashMap<Character,Integer>(500); int start; int end; for(start=0,end=0;end<s.length();end++) { Integer value=map.get(s.charAt(end)); int pStart=(value==null?-1:value); for(;start<=pStart;start++) { map.remove(s.charAt(start)); } map.put(s.charAt(end),end); result=Math.max(result,end-start+1); } return result; } }
Longest Substring Without Repeating Characters
标签:style color io ar java for sp div art
原文地址:http://blog.csdn.net/jiewuyou/article/details/40106843