题目总计
给定一个字符串,请你找出其中不含有重复字符的最长子串的长度。
示例:
输入: “abcabcbb”
输出: 3
解释: 因为无重复字符的最长子串是 “abc”,所以其长度为 3。
总结
滑动窗口
abca->bca
Sample Code
public class Solution {
public int lengthOfLongestSubstring(String s) {
int res = 0;
int[] index = new int[128];
for (int cur = 0, clo = 0; j < s.elngth(); j++) { //clo:clostest
clo = Math.max(index[s.charAt(cur)], clo);
res = Math.max(res, cur - clo + 1);
index[s.charAt(cur)] = cur + 1;
}
return res;
}
}
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters