题解 | #小猪摘水果#
小猪摘水果
https://www.nowcoder.com/practice/fdb76b9170dc4e689a7eceee97159d96
所用语言
Java
所用知识
数组
解题思路
遍历找最大的即可。
完整代码
public int mostFruitTree (int[] fruit) {
// write code here
int fast=10;
int max=fast;
for(int i=0;i<fruit.length;i++){
fast=fast+fruit[i];
if(fast>max) max=fast;
}
return max;
}
#小猪摘水果#