猿辅导 服务器端开发 笔经(已凉)

2020.08.01 晚上 笔试 1h30min

1)小猿的时间管理

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        PriorityQueue<int[]> queue = new PriorityQueue<>(new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) {
                if(o1[0] != o2[0]) {
                    return o1[0] - o2[0];
                }
                else {
                    return o1[1] - o2[1];
                }
            }
        });
        for(int i = 0; i < n; i++){
            int[] a = new int[2];
            for(int j = 0; j < 2; j++){
                a[j] = sc.nextInt();
            }
            queue.add(a);
        }

        int res = 1;
        while(!queue.isEmpty()) {
            int[] first = queue.poll();
            if(queue.isEmpty()) {
                break;
            }
            int[] second = queue.peek();

            if(second[0] < first[1]) {
                res++;
                int[] tmp = new int[2];
                tmp[0] = second[0];
                tmp[1] = first[1];
                queue.poll();
                queue.add(tmp);
            }
        }

        System.out.println(res);
    }
}


第一题0,第二题没做,第三题没做,菜到怀疑人生。

#笔经##校招##猿辅导##Java工程师#
全部评论
有三次机会呢,下次再战
点赞 回复
分享
发布于 2020-08-02 22:35
笔试压根没关系的吧。。。感觉就是个形式,反正今天已经收到面试通知了,我0.5
点赞 回复
分享
发布于 2020-08-03 21:31
博乐游戏
校招火热招聘中
官网直投

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务