哔哩哔哩 bilibili b站 4-19测开笔试答案

1 模拟

题意得小于10的都不行,然后1234都要一个

然后每次-4就行,因为-4后小于0的话,那么选别的也是算一次

然后发现超时,然后就骗测试样例了,每次都出4 10倍10倍的增加

 public int[] minimumNumber(int[] target) {
        int len = target.length;
        int[] ans = new int[len];
        for (int i = 0; i < len; i++) {
            if (target[i] < 10) {
                ans[i] = -1;
            } else {
                int val = target[i] - 10;
                int count = 4;

                while (val > 40000) {
                    val -= 40000;
                    count += 10000;
                }
                while (val > 4000) {
                    val -= 4000;
                    count += 1000;
                }
                while (val > 400) {
                    val -= 400;
                    count += 100;
                }
                while (val > 40) {
                    val -= 40;
                    count += 10;
                }
                while (val > 8) {
                    val -= 8;
                    count += 2;
                }
                while (val > 0) {
                    val -= 4;
                    count++;
                }
                ans[i] = count;
            }
        }
        return ans;
    }

2 停车

直接哈希存起来,然后有车出就删除,比较简单

public int parkingCapacity(int[] In, int[] Out) {
//        LinkedList<Integer> list = new LinkedList<>();
        int max = 0;
        int index = 0;
        HashSet<Integer> set = new HashSet<>();
        for (int i : In) {
            set.add(i);
            max = Math.max(max, set.size());
            while (!set.isEmpty() && set.contains(Out[index])) {
                set.remove(Out[index]);
                index++;
            }
        }
        return max;
    }

3 运算题,也比较简单吧,纯模拟,没隔壁那种手写计算器恶心

 public long calculate(String formula) {
        char[] cs = formula.toCharArray();
        int len = cs.length;
        for (int i = 0; i < len; i++) {
            if (Character.isDigit(cs[i])) {
//                数字
                String left = formula.substring(0, i);
                String right = formula.substring(i + 1, len);
                int leftNUM = 0;
                char[] leftCs = left.toCharArray();
                char[] rightCs = right.toCharArray();
//                int leftNum=0;
                String leftstr = "";
                for (int j = 0; j < leftCs.length; j++) {
                    int c2 = (leftCs[j] - 'a');
                    leftstr += String.valueOf(c2);
                }
                String rightStr = "";
                for (int j = 0; j < rightCs.length; j++) {
                    int c2 = (rightCs[j] - 'a');
                    rightStr += String.valueOf(c2);
                }
                System.out.println("rightStr = " + rightStr);
                System.out.println("leftstr = " + leftstr);
                Integer rightInt = Integer.valueOf(rightStr);
                Integer leftInt = Integer.valueOf(leftstr);
//                System.out.println();

                switch (cs[i]) {
                    case '1':
                        return leftInt+rightInt;
                    case '2':
                        return Math.abs(leftInt-rightInt);
                    case '3':
                        return (long) leftInt *rightInt;
                    case '4':
                        if (rightInt==0) return -1;
                        else return leftInt /rightInt;

                }
            }
        }
        // write code here
        return 0;
    }

第一次大厂3道全a,但是选择题没做好,估计机会不大

#技术岗笔试题求解##你的秋招第一场笔试是哪家##bilibili笔试##笔试##bilibili求职进展汇总#
全部评论
你有消息了么,面试什么的
点赞 回复 分享
发布于 04-22 15:42 上海
第一题如果减完10后数大于等于4,可以直接算出目前数是4的多少倍,然后减去这个倍数的4,不用每次10个10个
点赞 回复 分享
发布于 04-19 20:49 山东
楼主有遇到第三题95%的情况吗
点赞 回复 分享
发布于 04-19 20:45 北京

相关推荐

评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客企业服务