gpt4 book ai didi

java - 返回两个值的列表

转载 作者:行者123 更新时间:2023-12-02 09:36:34 26 4
gpt4 key购买 nike

链接:

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 31 2 3预期输出

0 0

最佳答案

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

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com