12
返回列表 发新帖
楼主: low910411
跳转到指定楼层
上一主题 下一主题
收起左侧

Expedia OA

🔗
 楼主| low910411 2019-3-4 13:43:29 | 只看该作者
全局:
lanluo_violet 发表于 2019-3-3 16:21
第一题我用了个counter,然后sort

第三题,挺巧妙的,求余数

我是用的java
第一题:
    static void customerSort(int[] arr) {
        if (arr == null || arr.length == 0) {
            return;
        }
        PriorityQueue<Map.Entry<Integer, Integer>> pq = new PriorityQueue<>(
                (o1, o2) -> {
                    if (o1.getValue() == o2.getValue()) {
                        return o1.getKey() - o2.getKey();
                    }
                    return o1.getValue() - o2.getValue();
                });

        HashMap<Integer, Integer> map = new HashMap<>();

        for (int i = 0; i < arr.length; i++) {
            if (map.containsKey(arr[i])) {
                map.put(arr[i], map.get(arr[i]) + 1);
            } else {
                map.put(arr[i], 1);
            }
        }

        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            pq.add(entry);
        }

        int point = 0;
        while (!pq.isEmpty()) {
            Map.Entry<Integer, Integer> entry = pq.poll();
            int frequency = entry.getValue();
            for (int i = 0; i < frequency; i++) {
                arr[point] = entry.getKey();
                point++;
            }
        }
    }


第三题 我用的方法和你应该一样的 也是LeetCode答案
    static long KSub(int k, int[] nums) {

        HashMap<Integer, Integer> map = new HashMap<>();
        int curMod = 0;
        int[] modCount = new int[k];

        for (int i = 0; i < nums.length; i++) {
            curMod = (curMod + (nums[i] % k) + k) % k;
            modCount[curMod]++;
        }

        int sum = 0;

        for (int i = 1; i < modCount.length; i++) {
            sum += (modCount[i] * (modCount[i] - 1)) / 2;
        }
        sum += (modCount[0] * (modCount[0] + 1)) / 2;
        return sum;
    }
回复

使用道具 举报

全局:
亲 求hirevue面经啊谢谢!!!
回复

使用道具 举报

全局:
谢谢亲分享 一定会有更好的的!加油!!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表