3181-2020-java-3-2

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这么好用而且方便调试

posted @ 2022-11-08 23:13  YaosGHC  阅读(24)  评论(0)    收藏  举报