项链问题 package ojtest; import java.util.Scanner; public class Sohu1 { public static int[] exist; public static boolean valid(){ for(int i=0;i<exist.length;i++) if(exist[i]<=0) return false; return true; } public static void add(char c){ if((c-'A')>=0&&('E'-c)>=0) exist[c-'A']++; } public static void remove(char c){ if((c-'A')>=0&&('E'-c)>=0) exist[c-'A']--; } public static int getmax(String str){ char[] chars=str.toCharArray(); int n=chars.length/2; int s=0,e=0,min=n; for(;e<chars.length;){ if(!valid()) add(chars[e++]); else{ min=Math.min(min, e-s); remove(chars[s++]); } } while(valid()){ min=Math.min(min, e-s); remove(chars[s++]); } return n-min; } public static void main(String[] args) { Scanner input=new Scanner(System.in); String str; while(input.hasNextLine()){ str=input.nextLine(); exist=new int[5]; System.out.println(getmax(str+str)); } } }
点赞 评论

相关推荐

06-12 16:00
天津大学 Java
牛客30236098...:腾讯坏事做尽,终面挂是最破防的 上次被挂了后我连简历都不刷了
点赞 评论 收藏
分享
昨天 13:51
门头沟学院 Java
周五投的,流程今天结束
投递地平线等公司7个岗位
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务