java - 返回两个值的列表

标签 java list arraylist

链接:

https://www.hackerrank.com/challenges/compare-the-triplets/problem?h_r=next-challenge&h_v=zen

公开课解决方案{

static List<Integer> compareTriplets(List<Integer> a, List<Integer> b) {
    ArrayList<Integer> aa= new ArrayList<Integer>();
   // List<Integer> bb=new ArrayList<>();
    int counta=0;
    int countb=0;
    aa.add(0);
    aa.add(1);
    for(int i=0;i<a.size();i++)
    {
        if(a.get(i)>b.get(i))
        {
          counta +=1;
          aa.set(0,counta);
        //  aa.set(1,0);

        }
        if(a.get(i)<b.get(i))
        {
            countb +=1;
              aa.set(1,countb);

        }

     /*  if(a.get(i)==b.get(i))
        {
            aa.set(0,0);
            aa.set(1,0);
        } */




    }

    return aa;


}

错误答案 输入

1 2 3 1 2 3 预期输出

0 0

最佳答案

aa.add(1); 将 Bob 的分数设置为默认值 1。要解决此问题,请将其替换为 aa.add(0);

关于java - 返回两个值的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57465432/

相关文章:

arrays - 如何在protobuf重复字段中发送0?

java - 多级菜单ArrayLists中对象的循环(Java)

java - 需要从绑定(bind)文件在 package-info.java 中生成 JAXB 注释

java - 用java获取特征值PCA

java - 当我在 Android 上扩展应用程序时,上下文在 Glide 上不起作用

java - Android MediaPlayer实时快进和快退按钮使用runnable实现

css - float 元素旁边的列表 : How to get list items in the right place?

python - 没有项目从列表中删除

java - 尝试更改卡的值(value)

java - 在 Java 中使用泛型时生成类转换异常