首页 > 编程知识 正文

美团笔试多少分能过,美团笔试是投了就发吗

时间:2023-05-03 10:16:46 阅读:195962 作者:1887

package meituanDianping;import java.util.*;/** * @author YanQiKing * @date 2019/8/22 13:07 */public class Main { public static void main(Stringdbdfk 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)); }}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。