Topicssubstring with the longest no repetition charactergiven a string, find the oldest string in which there are no repeating characters.
For example, in which the "abcabcbb" oldest string with no repeating characters is "abc" , its length is 3 .
For, the "bbbbb" oldest string with no repeating characters is "b" , length is 1 .
Solving
Use Hashmap,map to always join, exist, find the same character position, situation map, change subscript
Public classSolution {/** * @params:a String *@return: An integer*/ Public intlengthoflongestsubstring (String s) {//Write your code herehashmap<character,integer> map =NewHashmap<character,integer>(); if(s = =NULL) return0; if(S.length () <=1) returns.length (); intLongest =-1; for(inti = 0;i<s.length (); i++){ CharCH =S.charat (i); if(Map.containskey (CH)) {Longest=Math.max (Map.size (), longest); I=map.get (CH); Map.clear (); }Else{map.put (ch,i); }} longest=Math.max (Map.size (), longest); Map.clear (); returnlongest; }}
Lintcode Medium title: Longest substring without repeating characters longest non-repeating character substring