public class SubStringLength {
public static void main(String args[]) {
String str = "abcabcbb";
System.out.println(length(str));
}
public static int length(String str) {
int left = -1;
int ref = 0;
char[] char11 = str.toCharArray();
Map<Character,Integer> map = new HashMap<Character,Integer>();
for(int i=0;i<char11.length;i++) {
Character tt = char11[i];
if(map.containsKey(tt)) {
int temp = map.get(tt);
left = Math.max(left, temp);
}
map.put(tt, i);
ref = Math.max(ref, i-left);
}
return ref;
}
}
力扣算法第三道:找出不含重复字符的最长子串长度
最新推荐文章于 2024-08-13 14:56:59 发布