import java.io.*;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
String str = tokenizer.nextToken();
char[] chars = str.toCharArray();
HashSet<Character> set = new HashSet<>();
for(char ch:chars) set.add(ch);
HashSet<Character> tempSet;
int startIndex =-1,length= chars.length+1;
for(int i=0;i<chars.length;i++){
tempSet=new HashSet<>(set);
for(int j = i;j< chars.length;j++){
tempSet.remove(chars[j]);
if(tempSet.isEmpty()&&j-i<length){
startIndex=i;
length=j-i;
break;
}
}
}
for(int i=startIndex;i<=startIndex+length;i++) System.out.print(chars[i]);
}
}
感觉比赛的垃圾在线编辑器可没IDEA这么好用而且方便调试
标签:set,java,HashSet,chars,2020,3181,import,new From: https://www.cnblogs.com/yaocy/p/16871617.html