0422网易雷火笔试

Q1

public class Solution {
    public int putGems (int[] price, int k) {
        // write code here
        int n = price.length;
        if (n <= k) return 0;
        int[] values = new int[n - 1]; //  // 枚举n-1个分裂点,每个分裂点包含其左右两个值的和
        for (int i = 1; i < n; i++) values[i - 1] = price[i] + price[i - 1];
        Arrays.sort(values);
        int ans1 = 0, ans2 = 0;
        for (int i = 0; i < k - 1; i++) ans1 += values[i];
        for (int i = n - 2; i > n - 1 - k; i--) ans2 += values[i];
        return ans2 - ans1;
    }
}

Q2

public class Solution {
    public int getEstTime (int[][] map, int a_x, int a_y, int b_x, int b_y) {
        // write code here
        int m = map.length, n = map[0].length;
        boolean[][] vis = new boolean[m][n];
        int[][] dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
        Queue<int[]> queue = new ArrayDeque<>();
        queue.offer(new int[]{a_x, a_y});
        vis[a_x][a_y] = true;
        int ans = 0;
        while (!queue.isEmpty()) {
            for (int i = queue.size() - 1; i >= 0; i--) {
                int[] curr = queue.poll();
                if (curr[0] == b_x && curr[1] == b_y) return (ans & 1) == 0 ? (ans / 2) : (ans / 2 + 1);
                for (int[] dir : dirs) {
                    int x = curr[0] + dir[0], y = curr[1] + dir[1];
                    if (x < 0 || x >= m || y < 0 || y >= n || map[x][y] == 0 || vis[x][y]) continue;
                    queue.offer(new int[]{x, y});
                    vis[x][y] = true;
                }
            }
            ans++;
        }
        return -1;
    }
}

#网易##网易雷火##网易雷火笔试##网易笔试#
全部评论
为啥你们岗位的这么简单,开发岗的第二题我写了一百多行
1 回复
分享
发布于 2023-04-22 17:08 湖北
为啥跟我做的不一样啊
点赞 回复
分享
发布于 2023-04-22 16:00 河南
联想
校招火热招聘中
官网直投
第二题为啥一直只能通过50%
点赞 回复
分享
发布于 2023-04-22 16:01 江苏
简单的一批
点赞 回复
分享
发布于 2023-04-22 16:17 湖南
双机位咋搞
点赞 回复
分享
发布于 2023-04-22 16:58 湖北
大佬,第一题的思路咋想到的呀
点赞 回复
分享
发布于 2023-04-22 17:16 天津
第一题枚举分裂点真的秒 我第一题暴力回溯过的
点赞 回复
分享
发布于 2023-04-23 21:29 美国

相关推荐

投递巨人网络等公司8个岗位 >
点赞 评论 收藏
转发
头像
不愿透露姓名的神秘牛友
04-12 16:59
已编辑
1 本科985
点赞 评论 收藏
转发
5 6 评论
分享
牛客网
牛客企业服务