class Solution {
public int lengthOfLongestSubstring(String s) {
int [] map = new int[128];
int len = Integer.MIN_VALUE;
int start = 0;
int end = 0;
while(end < s.length()){
int c = s.charAt(end);
if(map[c] == 0){
map[c]++;
if(end - start + 1 >= len){
len = end - start + 1;
}
end++;
}
else{
map[s.charAt(start)] = 0;
start++;
}
}
if(len == Integer.MIN_VALUE) return 0;
return len;
}
}
[leetcode]3. Longest Substring Without Repeating Characters
最新推荐文章于 2021-12-03 15:58:56 发布