给定一个字符串 s
,请你找出其中不含有重复字符的 最长子串 的长度。
class Solution {
public int lengthOfLongestSubstring(String s) {
int max = 0;
int left = 0,right = 0;
char[] chs = s.toCharArray();
Set<Character> set = new HashSet<Character>();
for(int i = 0;i< chs.length;i++){
while(set.contains(chs[i])){
set.remove(chs[left++]);
}
set.add(chs[i]);
int temp = right - left +1;
right ++;
max = temp>max?temp:max;
}
return max;
}
}