You are viewing a single comment's thread. Return to all comments →
List<Integer> list=new ArrayList<>(); for(int i: s.toCharArray()){ list.add(i); } Collection<Long> values= list.stream().collect(Collectors.groupingBy(Function.identity(),Collectors.counting())).values(); long max=values.stream().max(Long::compare).orElse(0l); long min =values.stream().min(Long::compare).orElse(0l); long countMax=values.stream().filter(e->e==max).count(); long countMin=values.stream().filter(e->e==min).count(); if(min==max){ return "YES"; }else if(max-min==1 && countMax==1){ return "YES"; }else if(max-min==1 && countMin==1){ return "YES"; }else if(min==1 && countMin==1 && countMax==values.size()-1){ return "YES"; }else{ return "NO"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and the Valid String
You are viewing a single comment's thread. Return to all comments →
Java8