compareTriplets * three categories: clarity

    /**
     * compareTriplets
     * three categories: clarity, originality and difficulty
     * parameter is two array
     *  alice arr and bob arr
     *  compare tow array
     *  if arrAlice's rates element is greate than arrBob's rates element one by one
     *   Alice get one score
     *   else if arrAlice's rete element is less than arrBob's retes element one by one
     *   Bob get one score
     *   else equals null get any score
     *   return array[aliceScore,bobScore]
     *   constraints
     *   1<=a[i]<=100
     *   1<=b[i]<=100
     * @param a
     * @param b
     * @return
     */
    public static List<Integer> compareTriplets(List<Integer> a,List<Integer> b){
        if(a==null){
            return null;
        }
        if (a.isEmpty()){
            return null;
        }
        if (b==null){
            return null;
        }
        if (b.isEmpty()){
            return null;
        }
        for (Integer integer : a) {
            if (integer<1 || integer>100){
                return null;
            }
        }
        for (Integer integer : b) {
            if (integer<1 || integer>100){
                return null;
            }
        }
        int aliceScoreEleIndex0=a.get(0);
        int aliceScoreEleIndex1=a.get(1);
        int aliceScoreEleIndex2=a.get(2);
        int bobScoreEleIndex0=b.get(0);
        int bobScoreEleIndex1=b.get(1);
        int bobScoreEleIndex2=b.get(2);
        int aliceScore=0;
        HashSet<String> aliceScoreHashSet = new HashSet<>();
        int bobScore=0;
        HashSet<String> bobScoreHashSet = new HashSet<>();
        int count=0;
        while(true){
            if (aliceScoreEleIndex0>bobScoreEleIndex0){
                aliceScore+=1;
                String aliceScoreStr=aliceScore+"aliceScore_EleIndex0_great_than";
                aliceScoreHashSet.add(aliceScoreStr);
            } else if (aliceScoreEleIndex0<bobScoreEleIndex0) {
                bobScore+=1;
                String bobScoreStr=bobScore+"bobScore_EleIndex0_great_than";
                bobScoreHashSet.add(bobScoreStr);
            }
            if (aliceScoreEleIndex1>bobScoreEleIndex1){
                aliceScore+=1;
                String aliceScoreStr=aliceScore+"aliceScore_EleIndex1_great_than";
                aliceScoreHashSet.add(aliceScoreStr);
            } else if (aliceScoreEleIndex1<bobScoreEleIndex1) {
                bobScore+=1;
                String bobScoreStr=bobScore+"bobScore_EleIndex1_great_than";
                bobScoreHashSet.add(bobScoreStr);
            }
            if (aliceScoreEleIndex2>bobScoreEleIndex2){
                aliceScore+=1;
                String aliceScoreStr=aliceScore+"aliceScore_EleIndex2_great_than";
                aliceScoreHashSet.add(aliceScoreStr);
            } else if (aliceScoreEleIndex2<bobScoreEleIndex2) {
                bobScore+=1;
                String bobScoreStr=bobScore+"bobScore_EleIndex2_great_than";
                bobScoreHashSet.add(bobScoreStr);
            }
            count++;
            if (count>1000000){
                break;
            }
        }
        Set<String> aliceScoreSumSet=new HashSet<String>();
        for (String string : aliceScoreHashSet) {
            if (string.contains("aliceScore_EleIndex0_great_than")){
                aliceScoreSumSet.add("aliceScore_EleIndex0_great_than");
            } else if (string.contains("aliceScore_EleIndex1_great_than")) {
                aliceScoreSumSet.add("aliceScore_EleIndex1_great_than");
            }else if (string.contains("aliceScore_EleIndex2_great_than")){
                aliceScoreSumSet.add("aliceScore_EleIndex2_great_than");
            }
        }
        List<Integer> intList = new ArrayList<>();
        intList.add(aliceScoreSumSet.size());
        Set<String> bobScoreSumSet = new HashSet<String>();
        for (String string : bobScoreHashSet) {
            if (string.contains("bobScore_EleIndex0_great_than")){
                bobScoreSumSet.add("bobScore_EleIndex0_great_than");
            }else if (string.contains("bobScore_EleIndex1_great_than")){
                bobScoreSumSet.add("bobScore_EleIndex1_great_than");
            } else if (string.contains("bobScore_EleIndex2_great_than")) {
                bobScoreSumSet.add("bobScore_EleIndex2_great_than");
            }
        }
        intList.add(bobScoreSumSet.size());
        return intList;
    }

#牛客AI配图神器#

#你收到了团子的OC了吗##你觉得专业和学校哪个对薪资影响最大##牛客创作赏金赛##机械人值得去的国央企##国企vs私企,怎么选?#
Java技术 文章被收录于专栏

JavaEE技术 编程开发经验 企业通用技术

全部评论

相关推荐

05-26 10:24
门头沟学院 Java
qq乃乃好喝到咩噗茶:其实是对的,线上面试容易被人当野怪刷了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务