Given a string, find the length of the smallest string that does not contain repeating characters. Input: “abcabcbb” Output: 3 Explanation: Since the oldest string without repeating characters is “ABC”, its length is 3.

Class Solution {public int lengthOfLongestSubstring(String s) { Map<Character,Integer> Map = new HashMap(); int len = s.length(); int ans = 0; int start=0,end=0;for(; end<len; end++){ char c= s.charAt(end);if(map.containsKey(c)){
                start = Math.max(start,map.get(c));
            }
            ans = Math.max(ans,end-start+1);
            map.put(s.charAt(end),end+1);
        }
        returnans; }}Copy the code