int max(int i,int j){
if(i>j) return i;
return j;
}
int candy(int* ratings, int ratingsSize) {
int* left=(int*)malloc(sizeof(int)*ratingsSize);
int* right=(int*)malloc(sizeof(int)*ratingsSize);
for(int i=0;i<ratingsSize;i++){
if(i!=0&&ratings[i-1]<ratings[i]){
left[i]=left[i-1]+1;
}else{
left[i]=1;
}
}
int sum=0;
for(int i=ratingsSize-1;i>=0;i--){
if(i!=ratingsSize-1 && ratings[i]>ratings[i+1]){
right[i]=right[i+1]+1;
}else{
right[i]=1;
}
sum+=max(left[i],right[i]);
}
return sum;
}
标签:分发,ratingsSize,right,return,ratings,int,max,135,糖果 From: https://www.cnblogs.com/llllmz/p/18077356