private static void stringSubLen(String msg) {
int max = 0;
int left = 0;
Map<Character,Integer> map = new HashMap<>();
for (int i = 0; i < msg.length(); i++){
if (map.containsKey(msg.charAt(i))){
int diff = i - map.get(msg.charAt(i));
System.out.println(max +" , "+left +" , " + diff);
if (diff > left){
left = left + 1;
} else {
left = diff;
}
} else {
left ++ ;
}
max = Math.max(max,left);
map.put(msg.charAt(i), i);
}
System.out.println(max);
}
public static void main(String[] args) {标签:子串,map,int,max,msg,给定,字符串,diff,left From: https://www.cnblogs.com/eternality/p/17468553.html
//打印字符串不重复之间的间隔
Scanner scanner = new Scanner(System.in);
String text = scanner.next();
stringSubLen(text);
}