剑指 Offer 48. 最长不含重复字符的子字符串
3. 无重复字符的最长子串
题解:
双指针问题包括:
快慢指针、左右指针、滑动窗口、
这个题用滑动窗口
思路:维护一个窗口。不断滑动,然后更新答案,题目难度一般是中等或困难
参考链接:
https://blog.youkuaiyun.com/dai_jiyong/article/details/106796903多个方法
String.valueOf(s.charAt(i));
将charat类型转换为string类型
https://blog.youkuaiyun.com/celi_echo/article/details/100038366
map是无序的
indexof是获取该元素位置的索引,如果不存在,那么返回啥
https://blog.youkuaiyun.com/hahezhen/article/details/89154575
如果源字符中不存在目标字符,则返回-1
indexof的源码解析:https://blog.youkuaiyun.com/lzc_a/article/details/108951061
https://blog.youkuaiyun.com/ai7090/article/details/83881660
https://blog.youkuaiyun.com/ai7090/article/details/83881660
class Solution {
public int lengthOfLongestSubstring(String s) {
StringBuilder stringBuilder = new StringBuilder();
int l = 0;
for (int i = 0; i < s.length(); i++) {
//获取单个字符串
String c = String.valueOf(s.charAt(i));
//如果该元素存在,那么就是
if (stringBuilder.indexOf(c) >= 0) {
//那么就删除从0到该索引位置+1,
stringBuilder.delete(0, stringBuilder.indexOf(c) + 1);
}
//添加该元素
stringBuilder.append(c);
//l取最大值
l = Math.max(stringBuilder.length(), l);
}
return l;
}
}