Longest Substring Without Repeating Characters
Given a string, find the length of thelongest substringwithout 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 asubstring,"pwke"is asubsequenceand not a substring.
另附网上的答案一则.
http://www.cnblogs.com/grandyang/p/4480780.html
publicclassSolution{publicintlengthOfLongestSubstring(Strings){int[]m=newint[256];Arrays.fill(m,-1);intres=0,left=-1;for(inti=0;i<s.length();++i){left=Math.max(left,m[s.charAt(i)]);m[s.charAt(i)]=i;res=Math.max(res,i-left);}returnres;}}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。