基础班模板题 思路:双指针+哈希映射
Java 代码
class Solution {
public int lengthOfLongestSubstring(String s) {
char[] sc = s.toCharArray();
int[] queue = new int[300];
int max = 0;
for(int i = 0, j = 0; i < sc.length; i ++) {
queue[sc[i] - ' '] ++ ;
while(queue[sc[i] - ' '] > 1) {
queue[sc[j] - ' '] -- ;
j ++ ;
}
max = Math.max(max, i - j + 1);
}
return max;
}
}