【笔经】【bilibili】火速,刚做完就来了

选择题
知道前序中序求后序
tcp套接字哪个函数不会产生阻塞?bind
Docker架构的底层技术?不会
基本忘了,数据结构,数据库,操作系统,网络,组成原理都有吧,30道题,内容很多。
编程
1.给4个数,求是否满足24点。输入{7,2,1,10},输出true,因为7*2+1*10=24
用dfs来写,把4个数“压缩”成3个数,依次类推,判断最后arr[0]是否是24,AC了。
public boolean Game24Points (int[] arr) {
        // write code here
        if(arr.length == 1 && arr[0] == 24){
            return true;
        }
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                if(i == j){
                    continue;
                }
                int[] temp = new int[arr.length-1];
                int k = 0, l = 0;
                for (; l < arr.length; l++) {
                    if(l != i && l != j){
                        temp[k] = arr[l];
                        k++;
                    }
                }
                temp[k] = arr[i] + arr[j];
                if(Game24Points(temp)) return true;
                temp[k] = arr[i] - arr[j];
                if(Game24Points(temp)) return true;
                temp[k] = arr[i] * arr[j];
                if(Game24Points(temp)) return true;
                if(arr[j] != 0)
                    temp[k] = arr[i] / arr[j];
                if(Game24Points(temp)) return true;
            }
        }
        return false;
    }
2.判断括号是否匹配,好像之前做过了,经常出现的一道题目
用栈来做,如果匹配就弹出,最后判断栈是否为空。过了。
public boolean IsValidExp (String s) {
        // write code here
        if(s == null || s.equals("")){
            return true;
        }
        HashMap<Character,Character> m = new HashMap<Character, Character>();
        Stack<Character> st = new Stack<Character>();
        m.put(')','(');
        m.put(']','[');
        m.put('}','{');
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if(!m.containsKey(c)) st.add(c);
            else{
                if(st.size() == 0) return false;
                Character t = st.pop();
                if(m.get(c) != t) return false;
            }
        }
        return (st.empty() ? true : false);
    }

3.有1,4,16,64四种面额硬币和1024元的纸币,用纸币买了N元的东西N<=1024,求最少找回多少硬币
又双是背包,考了也有6,7场了,基本每场固定背包,100%
找出转移方程:是否花这枚硬币。
 public static int GetCoinCount (int N) {
        // write code here
        N = 1024 - N;
        int[] arr = {1, 4, 16, 64};
        int[] dp = new int[N+1];
        Arrays.fill(dp, N+1);
        dp[0] = 0;
        for (int i = 0; i <= N ; i++) {
            for (int j = 0; j < 4; j++) {
                if(i - arr[j] >= 0){
                    dp[i] = Math.min(dp[i], dp[i - arr[j]] + 1);
                }
            }
        }
        return dp[N];
    }


#哔哩哔哩##笔试题目#
全部评论
最后一题,1是4、16、64的因子,4是16、64的因子,16是64的因子,所以最少找回多少硬币,先考虑64,再考虑16,再考虑4再1就一遍下来了。 int count = 0; int num = N - 1024; count += num/64; num %= 64; count += num/16; num %= 16; count += num/4; num %= 4; count += num; cout<<count<<endl; 就可以了
3 回复
分享
发布于 2020-08-13 20:52
你们二三题有自测这个选项吗,为啥我二三题根本没有自测这个选项可以让我做调试。。
1 回复
分享
发布于 2020-08-13 21:07
联想
校招火热招聘中
官网直投
楼主你好,请问你是什么岗位?开发的话,是Java方向还是C++方向?或者其他语言方向~
点赞 回复
分享
发布于 2020-08-13 20:49
哈哈,笔试题就很友好,选择题有些确实不太行
点赞 回复
分享
发布于 2020-08-13 20:55
把第一题的代码拿去LeetCode跑了一下,好像没有过,LeetCode的题目连接:https://leetcode-cn.com/problems/24-game/
点赞 回复
分享
发布于 2020-08-13 21:38

相关推荐

7 10 评论
分享
牛客网
牛客企业服务