(已约面)6.11滴滴,北京网约车后端开发23届秋储实习笔试

#选择题不太会的

  • 树的度为5,其中度为1,2,3,4,5得节点个数为5,4,3,2,1 求子节点数
  • 文件传输服务器得数据连接端口
  • Runnable 相比Thread的优点
  • Linux更改目录文件的属组

编程题

序列拆分

输入多个 一个1-n的正整数序列,如果能拆分成一个递增序列和一个递减序列就输出Yes 否则输出No 例如 输入 8 6 1 3 2 4 5 输出 Yes

字符串替换

输入一个字符串 然后进行n次替换 每次将字符串里的 str1 替换成 str2 最后输出被替换n次的字符串

例如 输入 abcabc 2 bca abb bbb aac 输出 aaaacc

其他

赛码平台,还不需要***控,要摄像头 题目比较简单

我第一道编程题只过了18%脑袋大

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = 0;
        n = sc.nextInt();
        

        while (n-- > 0) {

            int len = 0;
            len = sc.nextInt();
            if (len == 1) {
                System.out.println("Yes");
                continue;
            }
            List<Integer> list = new ArrayList<Integer>();
            int temp = 0;

            int maxNum = Integer.MIN_VALUE;
            int maxIndex = 0;
            int minNum = Integer.MAX_VALUE;
            int minIndex = 0;

            for (int i = 0; i < len; ++i) {
                temp = sc.nextInt();
                list.add(temp);
                if (temp > maxNum) {
                    maxNum = temp;
                    maxIndex = i;
                }
                if (temp < minNum) {
                    minNum = temp;
                    minIndex = i;
                }
            }
            
            list.set(minIndex, -1);
            list.set(maxIndex, -1);
            
            for (int i = minIndex + 1; i < len; ++i) {
                if (list.get(i) != -1) {
                    if (list.get(i) > minNum) {
                        minNum = list.get(i);
                        list.set(i, -1);
                    }
                }
            }
            
            for (int i = maxIndex + 1; i < len; ++i) {
                if (list.get(i) != -1) {
                    if (list.get(i) < maxNum) {
                        maxNum = list.get(i);
                        list.set(i, -1);
                    }
                }
            }

            String res = "Yes";
            for (int i = 0; i < len; ++i) {
                if (list.get(i) != -1) {
                    res = "No";
                    break;
                }
            }
            System.out.println(res);
        }

        sc.close();
    }
}
大家可以投一投
# 最新进展
6.15 20:02收到面试邀请,以为挂了,不过楼主最近在准备期末,也感觉挺悬的。。。
#滴滴##笔试##滴滴实习#
全部评论
第二题答案有人发一下吗
3
送花
回复 分享
发布于 2022-06-11 21:45
第一题,回溯找到所有的递增序列,然后每次递归都判断剩下未标记的数字是否严格递减     static int[] book;     static int[] nums;     static int n;     static List<Integer> path = new ArrayList<>();     public static void main(String[] args)  {         nums = new int[]{8,6,1,3,2,4,5};         n = nums.length;         book = new int[n];         dfs(0,Integer.MIN_VALUE);     }     public static void dfs(int beg,int pre){         if(check())//每次check一下剩下的数组是否完全递减             System.out.println(path);         for(int i = beg; i < n; i++){//每次从上一个数的下标+1开始             if(book[i] == 0){                 if(nums[i] > pre){//如果本次是递增的才继续递归                     book[i] = 1;                     path.add(nums[i]);                     dfs(i+1,nums[i]);                     path.remove(path.size()-1);                     book[i] = 0;                 }             }         }     } //所有符合的解 [1, 3, 4, 5] [1, 2, 4, 5] [1, 4, 5]
2
送花
回复 分享
发布于 2022-06-11 22:34
蔚来
校招火热招聘中
官网直投
哈希表不行,这题我是回溯的,能过100%
1
送花
回复 分享
发布于 2022-06-11 21:30
就没有用python的吗,第一题直接放弃了😭
1
送花
回复 分享
发布于 2022-06-11 22:52
楼主有笔试结果了吗?😁
1
送花
回复 分享
发布于 2022-06-12 22:52
{"pureText":"","imgs":[{"alt":"discuss_165****115090.jpeg","height":889,"localSrc":"content://com.miui.gallery.open/raw/%2Fstorage%2Femulated%2F0%2FTencent%2FQQ_Images%2F1a79e723b7994205.png","src":"https://uploadfiles.nowcoder.com/message_images/20220613/525666935_1655051114658/discuss_1655051115090.jpeg","width":453},{"alt":"discuss_165****122520.jpeg","height":581,"localSrc":"content://com.miui.gallery.open/raw/%2Fstorage%2Femulated%2F0%2FTencent%2FQQ_Images%2F43b5692829b6e2a8.png","src":"https://uploadfiles.nowcoder.com/message_images/20220613/525666935_1655051122052/discuss_1655051122520.jpeg","width":668}]}
1
送花
回复 分享
发布于 2022-06-13 00:25
我第一题也没过,楼主有答案吗,我想看看😭
点赞
送花
回复 分享
发布于 2022-06-11 21:17
第一题我用深度。。。几行就a了
点赞
送花
回复 分享
发布于 2022-06-11 23:27
是秋储嘛兄弟?
点赞
送花
回复 分享
发布于 2022-06-14 19:39
杭州还是北京呀?
点赞
送花
回复 分享
发布于 2022-06-16 09:40

相关推荐

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