题目
参考《算法小抄》重的解法,重点理解!!!
class Solution {
public int lengthOfLongestSubstring(String s) {
if (s.length() < 2) {
return s.length();
}
char[] array = s.toCharArray();
int left = 0, right = 0, res = 0;
int[] count = new int[256];
while (right < array.length) {
char cur = array[right];
++right;
++count[cur];
while (count[cur] > 1) {
char d = array[left];
++left;
--count[d];
}
res = Math.max(res, right - left);
}
return res;
}
}