题目:
给定一个字符串 s
,请你找出其中不含有重复字符的 最长子串 的长度
解答:
class Solution {
public int lengthOfLongestSubstring(String s) {
int count = 0;
int res = 0;
Map<Character,Integer> map = new HashMap<>();
for(int end = 0,start = 0;end < s.length();end++){
char index = s.charAt(end);
if(map.containsKey(index)){
start = Math.max(map.get(index), start);
}
res = Math.max(res, end - start + 1);
map.put(s.charAt(end), end + 1);
}
return res;
}
}