题解 | 小猪摘水果
小猪摘水果
https://www.nowcoder.com/practice/fdb76b9170dc4e689a7eceee97159d96
- 前缀和
import java.util.*;
public class Solution {
public int mostFruitTree (int[] fruit) {
final int n = fruit.length;
int max = Math.max(0, fruit[0]);
for (int i = 1; i < n; ++i) {
fruit[i] += fruit[i - 1];
max = Math.max(max, fruit[i]);
}
return 10 + max;
}
}
