class Solution {
private Map<Character, Integer> map = new HashMap<>();
public int lengthOfLongestSubstring(String s) {
int i = 0;
int max = 0;
char temp = '\0';
int start = -1;
for (i = 0; i < s.length(); i ++) {
temp = s.charAt(i);
if (map.get(temp) != null) {
start = Math.max(map.get(temp) , start);
}
max = Math.max(i - start, max);
map.put(temp, i);
}
return max;
}
}
网友评论