oppo测开笔试2022.9.2

为什么上午做题的同学说好简单,我下午做,咋就那么难呢

选择难死了

算法第一题就g了
1、wakelock贡献值
咱就是说,这个题,花了1个小时,最后通过率20%(下面是通过率20%的代码······)
public ArrayList<Integer> getWakeLockContrib (ArrayList<ArrayList<Integer>> wakeLock) {
        // write code here
        ArrayList<Integer> a=wakeLock.get(0);
        ArrayList<Integer> b=wakeLock.get(0);
        int asize=a.size();
        int bsize=b.size();
        int asum=0,bsum=0;
        for(int i=0;i<asize;i+=2){
            asum+=a.get(i+1)-a.get(i);
        }
        for(int j=0;j<bsize;j+=2){
            bsum+=b.get(j+1)-b.get(j);
        }
        int sub=0;
        if(asize>=bsize){
            for(int i=0;i<bsize;i+=2){
                if(a.get(i+1)>b.get(i+1) && a.get(i)<b.get(i)){
                    sub=(b.get(i+1)-b.get(i))/2;
                }else if(a.get(i+1)<b.get(i+1) && a.get(i)>b.get(i)){
                    sub=(a.get(i+1)-a.get(i))/2;
                }else if(a.get(i)<b.get(i) && a.get(i+1)>b.get(i) && a.get(i+1)<b.get(i+1)){
                    sub=(a.get(i+1)-b.get(i))/2;
                }else if(b.get(i)<a.get(i) && b.get(i+1)>a.get(i) && b.get(i+1)<a.get(i+1)){
                    sub=(b.get(i+1)-a.get(i))/2;
                }
                asum-=sub;bsum-=sub;
            }
        }else{
            for(int i=0;i<asize;i+=2){
                if(a.get(i+1)>b.get(i+1) && a.get(i)<b.get(i)){
                    sub=(b.get(i+1)-b.get(i))/2;
                }else if(a.get(i+1)<b.get(i+1) && a.get(i)>b.get(i)){
                    sub=(a.get(i+1)-a.get(i))/2;
                }else if(a.get(i)<b.get(i) && a.get(i+1)>b.get(i) && a.get(i+1)<b.get(i+1)){
                    sub=(a.get(i+1)-b.get(i))/2;
                }else if(b.get(i)<a.get(i) && b.get(i+1)>a.get(i) && b.get(i+1)<a.get(i+1)){
                    sub=(b.get(i+1)-a.get(i))/2;
                }
                asum-=sub;bsum-=sub;
            }
        }
        ArrayList<Integer> array=new ArrayList<>();
        array.add(asum);
        array.add(bsum);
        return array;
    }


2、
长字符匹配逆序短字符,遇见* 默认匹配,返回长字符中第一次匹配完成的下标(ac)
public int findStr (String str, String mod) {
        // write code here
        if(mod.length()==0) return 0;
        StringBuffer sb=new StringBuffer(mod);
        String modd=sb.reverse().toString();

        for(int i=0;i<str.length();i++){
            int a=i,j=0;
            while(str.charAt(a)==modd.charAt(j) || modd.charAt(j)=='*'){
                if(j==modd.length()-1){
                    return a;
                }
                a++;
                j++;
                if(a>=str.length() || j>=mod.length()) break;
            }
        }
        return -1;
    }


3、
翻转链表(ac
public ListNode reverseList (ListNode head) {
        // write code here
        ListNode pre=null;
        ListNode tmp=head;
        ListNode next;
        while(tmp!=null){
            next=tmp.next;
            tmp.next=pre;
            pre=tmp;
            tmp=next;
        }
        return pre;
        
    }


#OPPO笔试##面经笔经##23届秋招笔面经#
全部评论
第一题开个map对占用的区间加1,然后遍历的时候贡献就是1除以区间上数字,但是只能过80,不知道哪出问题了
点赞 回复
分享
发布于 2022-09-02 17:48 陕西
ak了哈哈 比较简单
1 回复
分享
发布于 2022-09-02 17:53 湖北
滴滴
校招火热招聘中
官网直投
第一题ac了,像有次华为的笔试题,直接区间拆分就好了
点赞 回复
分享
发布于 2022-09-02 19:37 四川
第一题很简单啊,就差分,还有通过一个题叫ac,全通过叫ak
点赞 回复
分享
发布于 2022-09-02 20:31 江苏
为啥我做题之前不看这个帖子呢??做完之后想起来搜一下了 。。。。
点赞 回复
分享
发布于 2022-09-02 21:01 北京
第一题只过了80,求教
点赞 回复
分享
发布于 2022-09-02 22:02 江苏
确实上午的好简单,下午难爆了
点赞 回复
分享
发布于 2022-09-02 17:01 江苏
第一题python ac代码 akelock = [[1234, 1240], [1236, 1238, 1245, 1250]] count = {} for wake_list in wakelock:     for i in range(len(wake_list)):         if i % 2 == 0:             left = wake_list[i]             right = wake_list[i+1]             for num in range(left, right):                 count[num] = count.get(num, 0) + 1 res = [] for wake_list in wakelock:     contribute = 0     for i in range(len(wake_list)):         if i % 2 == 0:             cur_contribute = 0             left = wake_list[i]             right = wake_list[i+1]             for num in range(left, right):                 cur_contribute += 1/count[num]             contribute += int(cur_contribute)     res.append(int(contribute)) print(res)
2 回复
分享
发布于 2022-09-03 12:52 湖北
第一题怎么做呀?
1 回复
分享
发布于 2022-09-02 17:51 江苏
题目一样    第一题有点难度的,不过只用减法  不考虑不同应用重复的话能过40
点赞 回复
分享
发布于 2022-09-02 16:50 上海
刚考完 一样的题目😂
点赞 回复
分享
发布于 2022-09-02 17:36 广东
第一题分区间过了80
点赞 回复
分享
发布于 2022-09-02 17:45 北京
纯纯kpi唉
点赞 回复
分享
发布于 2022-09-02 20:28 北京
都是一样的题目,编程ak了,就是选择题有点恼火
点赞 回复
分享
发布于 2022-09-02 20:38 重庆
刚考完,题一样,60,70,100
点赞 回复
分享
发布于 2022-09-02 20:39 江苏
第二题本想手写kmp结果细节想不起来了
点赞 回复
分享
发布于 2022-09-02 22:35 上海
哈哈哈,上午做的,特简单,半小时所有题目完成。
点赞 回复
分享
发布于 2022-09-02 23:02 江苏
第一题蛮难的。。。做了好久,才看到要区间转型成整数不能算完再转。。。
点赞 回复
分享
发布于 2022-09-02 23:12 上海

相关推荐

17 52 评论
分享
牛客网
牛客企业服务