Closed 1e0n-xx closed 3 years ago
java的版本好像跑不出来?
public int candy(int[] ratings) {
if(ratings==null || ratings.length == 0)
return 0;
int len = ratings.length;
int [] c = new int [len];
Arrays.fill(c,1);
for (int i = 1; i < len; i++) {
if(ratings[i]>ratings[i-1])
c[i]++;
}
for (int i = len-1; i >0; i--) {
if (ratings[i] < ratings[i-1]) {
c[i-1] = Math.max(c[i-1], c[i] + 1);
}
}
int ans = 0;
for(int i : c)
ans+=i;
return ans;
}
您好,第一个for loop应该是c[i] = c[i-1] + 1。 请不要再在issue提帮忙debug的需求,谢谢。
如果测试用例是这个的话 [1,2,87,87,87,2,1] 好像跑不过?