标签:shm 滑动 ble dong put png 子串 https str
public int lengthOfLongestSubstring(String s) {
if (s.length() == 0) return 0;
HashMap<Character, Integer> map = new HashMap<Character, Integer>();
int max = 0;
int left = 0;
for(int i = 0; i < s.length(); i ++){
// 如果出现重复的,那么两个重复的字符之间就是不重复的字符串??
if(map.containsKey(s.charAt(i))){
// 记录重复的字符的下一个字符的位置
left = Math.max(left,map.get(s.charAt(i)) + 1);
}
// 覆盖字符重复的位置,
map.put(s.charAt(i),i);
// 计算最大值
max = Math.max(max, i - left + 1);
}
return max;
}
标签:shm 滑动 ble dong put png 子串 https str
原文地址:https://www.cnblogs.com/bears9/p/13624970.html