美团笔试,第一题AC,第二题Leetcode269

public class 美团骑手包裹区间分组 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < line.length(); i++) {
            map.put(line.charAt(i), i);
        }
        int index = 0;
        int count = 0;
        for (int i = 0; i < line.length(); i++) {
            char c = line.charAt(i);
            count = Math.max(count, map.get(c));
            if (i == count) {
                if (count == line.length() - 1) {
                    System.out.println(count + 1 - index);
                    break;
                } else {
                    System.out.println(count + 1 - index + "");
                    index = count + 1;
                }
            }
        }
    }
}
public class 火星文字典 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] strs = line.split(" ");
        StringBuilder sb = new StringBuilder();
        Map<Character, Integer> degree = new HashMap<>();
        for (String str : strs) {
            for (char c : str.toCharArray()) {
                degree.put(c, 0);
            }
        }
        Map<Character, Set<Character>> map = new HashMap<>();
        for (int i = 0; i < strs.length - 1; i++) {
            String cur = strs[i];
            String next = strs[i + 1];
            int len = Math.min(cur.length(), next.length());
            for (int j = 0; j < len; j++) {
                char c1 = cur.charAt(j);
                char c2 = next.charAt(j);
                if (c1 != c2) {
                    Set<Character> set = new HashSet<>();
                    if (map.containsKey(c1)) set = map.get(c1);
                    if (!set.contains(c2)) {
                        set.add(c2);
                        map.put(c1, set);
                        degree.put(c2, degree.get(c2) + 1);
                    }
                    break;
                }
            }
        }
        LinkedList<Character> queue = new LinkedList<>();
        for (Map.Entry<Character, Integer> entry : degree.entrySet()) {
            if (entry.getValue() == 0) {
                queue.add(entry.getKey());
            }
        }

        while (!queue.isEmpty()) {
            char parent = queue.poll();
            sb.append(parent);
            if (map.containsKey(parent)) {
                for (char child : map.get(parent)) {
                    degree.put(child, degree.get(child) - 1);
                    if (degree.get(child) == 0) queue.offer(child);
                }
            }
        }
        System.out.println(sb.toString());
    }
}
第一题A了,第二题有点蒙,然后直接输出 invalid,AC 36,这是刚找的网上的代码 

#美团##leetcode#
全部评论
第二题我把给的案例都输了,过55%
点赞 回复 分享
发布于 2019-08-22 16:36

相关推荐

群星之怒:1.照片可以换更好一点的,可以适量P图,带一些发型,遮住额头,最好穿的正式一点,可以适当P图。2.内容太少。建议添加的:求职意向(随着投递岗位动态更改);项目经历(内容太少了建议添加一些说明,技术栈:用到了什么技术,还有你是怎么实现的,比如如何确保数据传输稳定的,角色注册用到了什么技术等等。)项目经历是大头,没有实习是硬伤,如果项目经理不突出的话基本很难过简历筛。3.有些内容不必要,比如自我评价,校内实践。如果实践和工作无关千万别写,不如多丰富丰富项目。4.排版建议:建议排版是先基础信息,然后教育背景(要突出和工作相关的课程),然后专业技能(一定要简短,不要长篇大论,写你会什么,会的程度就可以),然后是项目经历(一定要详细,占整个简历一定要超过一半,甚至超过百分之70都可以)。最后如果有一部分空白的话可以填补上校内获得的专业相关的奖项,没有就写点校园经历和自我评价。5.技术一定要够硬,禁得住拷打。还有作息尽量保证正常,不要太焦虑。我24双非本科还是非科班,秋招春招各找了一段实习结果都没有转正,当时都想噶了,最后6月份在校的尾巴也找到一份工作干到现在,找工作有时很看运气的不要急着自我否定。 加油
点赞 评论 收藏
分享
评论
点赞
16
分享

创作者周榜

更多
牛客网
牛客企业服务