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

本文作者:YaosGHC

本文链接:https://www.cnblogs.com/yaocy/p/16871617.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   YaosGHC  阅读(18)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起