京东笔试:100%,27%

第一题合唱团身高分组,第二个用例给的很有迷惑性,我看了很久才发现69079936 236011312 77957850 653604087 443890802 277126428 755625552 768751840 993860213 882053548
这个用例,69079936 236011312 77957850排序后是 69079936 77957850  236011312 ,236011312 是9位数。。。。。
然后就可以AC了:
import java.util.*;

/**
 * @author :week
 * @date :Created in 2019-08-24 18:48
 * @description:
 * @modified By:
 * @version: 1.0.0
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int[] H=new int[N];
        int[] tmp=new int[N];
        for(int i=0;i<N;i++){
            H[i]=sc.nextInt();
            tmp[i]=H[i];
        }
        Arrays.sort(tmp);
        Map<Integer,Integer> map =new HashMap<Integer,Integer>();
        int count=0;
        for(int i=0;i<N;i++){
            int a=H[i];
            int b=tmp[i];
            if(map.containsKey(a)){
                map.put(a,map.get(a)+1);
            }else{
                map.put(a,1);
            }
            if(map.containsKey(b)){
                map.put(b,map.get(b)-1);
            }else{
                map.put(b,-1);
            }
            if(map.containsKey(a)&&map.get(a)==0){
                map.remove(a);
            }
            if(map.containsKey(b)&&map.get(b)==0){
                map.remove(b);
            }
            if(map.size()==0){
                count++;
            }
        }
        System.out.println(count);


    }
}
第二题:不知道字典序怎么贪。。来回倒腾,永远27%。。
import java.util.*;

/**
 * @author :week
 * @date :Created in 2019-08-24 18:49
 * @description:
 * @modified By:
 * @version: 1.0.0
 */
public class Main {
    private static boolean[][] grah;
    private static int[] boycount;
    private static int[] grilcount;
    private static int n;
    private static int m;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        m=sc.nextInt();
        grah=new boolean[n][n];
        boycount =new int[n];
        grilcount=new int[n];
        for(int i=0;i<m;i++){
            int x=sc.nextInt();
            int y=sc.nextInt();
            int min=Math.min(x,y);
            int max=Math.max(x,y);
            x=min-1;
            y=max-n-1;
            boycount[x]++;
            grilcount[y]++;
            grah[x][y]=grah[y][x]=true;
        }
        int[] L=findMax(boycount);
        int[] R=findMax(grilcount);
        int count=0;
        List<Integer> res=new ArrayList<Integer>();
        while(true){
            if(L[0]==-1&&R[0]==-1){
                break;
            }
            count++;
            if(L[1]>=R[1]){
                deleteNode(L[0],true);
                res.add(L[0]+1);
            }else{
                deleteNode(R[0],false);
                res.add(R[0]+1+n);
            }
            L=findMax(boycount);
            R=findMax(grilcount);
        }
        System.out.println(count);
        Collections.sort(res, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                int t1=o1;
                int t2=o2;
                while(t1>10){
                    t1=t1/10;
                }
                while(t2>10){
                    t2=t2/10;
                }
                return t1-t2;
            }
        });
        for(int i=0;i<res.size();i++){
            System.out.println(res.get(i));
        }
    }
    public static void deleteNode(int index,boolean tag){
        if(tag){
            boycount[index]=0;
            for(int i=0;i<n;i++){
                if(grah[index][i]){
                    grah[index][i]=false;
                    grilcount[i]--;
                }
            }
        }else{
            grilcount[index]=0;
            for(int i=0;i<n;i++){
                if(grah[i][index]){
                    grah[i][index]=false;
                    boycount[i]--;
                }
            }
        }
    }
    public static int[] findMax(int[] num){
        int max=0;
        int index=-1;
        for(int i=0;i<num.length;i++){
            if(num[i]>max){
                max=num[i];
                index=i;
            }
        }
        return new int[]{index,max};
    }
}


#京东##笔试题目##Java工程师#
全部评论
点赞 回复 分享
发布于 2019-08-24 21:46
import java.util.*; public class Main {     public static void main(String[] args) {         Scanner input = new Scanner(System.in);         int len = Integer.valueOf(input.nextLine());         String s = input.nextLine();         boolean isBig = false;         int count = 0;         for (int i=0; i < s.length(); i++ ){             if (isBig) {                 if (Character.isUpperCase(s.charAt(i)))                     continue;                 else {                     count++;                     if (i + 1 < s.length() && Character.isLowerCase(s.charAt(i + 1)))                         isBig = false;                 }             }             else {                 if (Character.isLowerCase(s.charAt(i)))                     continue;                 else {                     count++;                     if (i+1<s.length()&&Character.isUpperCase(s.charAt(i+1)))                         isBig=true;                 }             }         }         count += len;         System.out.println(count);     } } AC
点赞 回复 分享
发布于 2019-08-30 16:34
大佬说一下第一题思路吗?
点赞 回复 分享
发布于 2019-08-24 22:01
哥们,你收到面试约了,咱们俩编程题A的差不多
点赞 回复 分享
发布于 2019-08-30 21:21
楼主你好,看你第一题代码,代码清晰,思路也很好理解,但是有点不解,你算的H与temp(排过序的)的连续子数组是同一集合的个数,但是这个为什么是最后的答案呢? 比如测试用例H=[2 1 4 5 3 6 8 7],temp=[1 2 3 4 5 6 7 8], 连续子数组[2 1]、[4 5 3]、[6]、[8、7]满足要求,答案是4,最后算的是最多划分的个数,连续子数组是同一集合的个数和这感觉联系不上来呀,比如我可以仅在1和4之间切一刀,我也可以在1和4之间以及3和6之间切,共切两刀,如果这样组合就有不止4中情况,求指点,感谢
点赞 回复 分享
发布于 2019-08-25 10:02
同求第一题思路
点赞 回复 分享
发布于 2019-08-24 22:40
这是什么岗位的题目
点赞 回复 分享
发布于 2019-08-24 22:11
tql。。。我不配和东哥做兄弟。。。我连题都没读懂。。
点赞 回复 分享
发布于 2019-08-24 21:47

相关推荐

最近群里有很多同学找我看简历,问问题,主要就是集中在明年三月份的暑期,我暑期还能进大厂嘛?我接下来该怎么做?对于我来说,我对于双非找实习的一个暴论就是title永远大于业务,你在大厂随随便便做点慢SQL治理加个索引,可能就能影响几千人,在小厂你从零到一搭建的系统可能只有几十个人在使用,量级是不一样的。对双非来说,最难的就是约面,怎么才能被大厂约面试?首先这需要一点运气,另外你也需要好的实习带给你的背书。有很多双非的同学在一些外包小厂待了四五个月,这样的产出有什么用呢?工厂的可视化大屏业务很广泛?产出无疑是重要的,但是得当你的实习公司到了一定的档次之后,比如你想走后端,那么中厂后端和大厂测开的选择,你可以选择中厂后端(注意,这里的中厂也得是一些人都知道的,比如哈啰,得物,b站之类,不是说人数超过500就叫中厂),只有这个时候你再去好好关注你的产出,要不就无脑大厂就完了。很多双非同学的误区就在这里,找到一份实习之后,就认为自己达到了阶段性的任务,根本不再投递简历,也不再提升自己,玩了几个月之后,美其名曰沉淀产出,真正的好产出能有多少呢?而实际上双非同学的第一份实习大部分都是工厂外包和政府外包!根本无产出可写😡😡😡!到了最后才发现晚了,所以对双非同学来说,不要放过任何一个从小到中,从中到大的机会,你得先有好的平台与title之后再考虑你的产出!因为那样你才将将能过了HR初筛!我认识一个双非同学,从浪潮到海康,每一段都呆不久,因为他在不断的投递和提升自己,最后去了美团,这才是双非应该做的,而我相信大部分的双非同学,在找到浪潮的那一刻就再也不会看八股,写算法,也不会打开ssob了,这才是你跟别人的差距。
迷茫的大四🐶:我也这样认为,title永远第一,只有名气大,才有人愿意了解你的简历
双非本科求职如何逆袭
点赞 评论 收藏
分享
评论
4
36
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务