学而思 前端笔试

选择题都是一些 机器学的和操作系统的东西。。 感觉很迷。
算法 第一道 AC
package com.company; import java.util.*; public class ListNode { public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Set<Integer> set = new HashSet<>();
        String rs = ""; while (sc.hasNextInt()){ int tmp = sc.nextInt();
            tmp = Math.abs(tmp); if(!set.contains(tmp)){
                rs += tmp + " ";
                set.add(tmp);
            }
        }
        System.out.println(rs);
    }
}
第二道,感觉是时间复杂度高了,不记得堆排序咋写了,尴尬。 67%
大概思路  维持一个数组,让数组第一个为改数组的最小值。 不断筛选,等我去看看真正的堆排序咋写再补充一个。
package com.company; import java.util.*; public class dui { public static void main(String[] args){
        Scanner sc = new Scanner(System.in); float n = sc.nextFloat(); int[] tmp = new int[(int) Math.floor((Math.ceil(n*0.1*0.01)))]; for (int i=0;i<tmp.length;i++){
            tmp[i] = sc.nextInt();
        } getMin(tmp); for (int i=tmp.length;i<n;i++){ int in = sc.nextInt(); if (in > tmp[0]){
                tmp[0] = in; getMin(tmp);
            }
        } for (int i=0;i<tmp.length;i++){
            System.out.println(tmp[i]);
        }
    } public static void getMin(int[] tmp){ int index = 0; int min = tmp[0]; int tmep = 0; for (int i=0;i<tmp.length;i++){ if (tmp[i] == 0) continue; if (tmp[i] < min){
                index = i;
                min = tmp[min];
            }
        }
        tmep = min;
        tmp[0] = min;
        tmp[index] = tmep;
    }
}

#笔试题目##学而思##前端工程师##笔经#
全部评论
我看到你发的帖才想起来,题目下面提示用堆。。我做的时候给忘了,用数组AC100%了,还不会C用的Java,感觉没分了哈哈
点赞 回复 分享
发布于 2019-09-02 20:52
是有点迷。。
点赞 回复 分享
发布于 2019-09-02 21:00

相关推荐

点赞 评论 收藏
分享
什么时候才能有offer啊_:十年前我还在刺激战场研究跳伞的底层原理呢
投递牛客等公司
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务