链接:
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/