I got below code accepted, let me explain a little. I use a int[] candy and go through ratings to set values for candy, candy[i] will be 1 if ratings[i] equals to ratings[i - 1], candy[i] will be candy[i - 1] + 1 if ratings[i] is bigger than ratings[i - 1], in the process I maintain a variable to track the last top rating so that in the case ratings[i] < ratings[i - 1], I can check backwards to make sure higher ratings get more candy until I reach last top rating.

My question is that, see in the inner for loop, I first use candy[j] = candy[j + 1] + 1; and got TLE, but got accepted if I use candy[j]++;

Is former line of code so slower than the latter one?

```
public int candy(int[] ratings) {
int len = ratings.length;
if (len <= 1) return len;
int[] candy = new int[len];
candy[0] = 1;
int lastTop = 0;
for (int i = 1; i < len; i++){
if (ratings[i] == ratings[i - 1]){
candy[i] = 1;
lastTop = i;
}
if (ratings[i] > ratings[i - 1]){
candy[i] = candy[i - 1] + 1;
lastTop = i;
}
else {
candy[i] = 1;
for (int j = i - 1; j >= lastTop; j--){
if (candy[j] <= candy[j + 1]){
//candy[j] = candy[j + 1] + 1; //TLE !
candy[j]++; //but this passes
}
else {
break;
}
}
}
}
int total = 0;
for (int i = 0; i < len; i++){
total += candy[i];
}
return total;
}
```