package meituanDianping;
import java.util.*;
/**
* @author YanQiKing
* @date 2019/8/22 13:07
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine().trim();
ArrayList<ArrayList<Integer>> al = new ArrayList<>();
HashMap<Character,Integer> hm = new HashMap<>();
int in = 0;
for (int i=0;i<str.length();i++) {
char c = str.charAt(i);
if (null==hm.get(c)){
hm.put(c,in);
al.add(new ArrayList<>());
al.get(in).add(i); // 代表开始 ArrayList本质是一个数组
al.get(in).add(i); //代表结束
in++;
}else {
int index = hm.get(c);
ArrayList<Integer> minmax = al.get(index);
if (i > minmax.get(1)) {
minmax.set(1,i);
}
}
}
ArrayList<Integer> res = new ArrayList<>();
int low = 0;
int temp = al.get(0).get(1);
for (int i=1;i<al.size();i++) {
if (temp<al.get(i).get(0)){
res.add(temp-low+1);
low=al.get(i).get(0);
temp= al.get(i).get(1);
}
if (temp>al.get(i).get(1)) {
continue;
}else {
temp=al.get(i).get(1);
}
}
res.add(temp-low+1);
for (int i=0;i<res.size() - 1;i++) {
System.out.println(res.get(i)+" ");
}
System.out.println(res.get(res.size() - 1));
}
}
美团笔试8.22
最新推荐文章于 2024-08-03 16:44:15 发布