typedef struct node{
int fruit;
int lastindex;
}node;
int totalFruit(int* fruits, int fruitsSize) {
node f[2];
f[0].fruit=-1,f[1].fruit=-1;
int max=0,sum=0;
int tail=0;
while(tail<fruitsSize){
int i=0;
for(;i<=1;i++){
if(f[i].fruit==-1){
f[i].fruit=fruits[tail];
f[i].lastindex=tail++;
sum++;
break;
}else if(f[i].fruit==fruits[tail]){
sum++;
tail++;
break;
}
}
if(sum>max) max=sum;
if(i==2){
if(f[0].lastindex<f[1].lastindex){
tail=f[1].lastindex;
f[0].fruit=-1;
}else{
tail=f[0].lastindex;
f[1].fruit=-1;
}
sum=0;
}
}
return max;
}
已经想到机试怎么死的了,小错误,逻辑错误一大堆,还没有调试器。直接G
标签:node,水果,904,int,max,sum,lastindex,fruit,成篮 From: https://www.cnblogs.com/llllmz/p/18070596