题解 | #小猪摘水果#
小猪摘水果
https://www.nowcoder.com/practice/fdb76b9170dc4e689a7eceee97159d96
知识点:数组 模拟
思路:遍历就好了,记住最大值和前面的最大值和,比较最大值和最大值和即可
编程语言:java
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param fruit int整型一维数组
* @return int整型
*/
public int mostFruitTree (int[] fruit) {
// write code here
//纯粹的模拟
int start = 10;
int max = 10;
for (int i = 0; i < fruit.length; i++) {
start+=fruit[i];
max = Math.max(start,max);
}
return max;
}
}
查看2道真题和解析
