题目考察的知识点
数组遍历,对于题目的理解
题目解答方法的文字分析
题目的描述不清晰,看了别人答案才理解是想要求数组从第一棵树到哪个位置的总和是最大的。题目的净差值在本题的应用感觉不是很合适。
本题解析所用的编程语言
使用Java代码解答
完整且正确的编程代码
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param fruit int整型一维数组 * @return int整型 */ public int mostFruitTree (int[] fruit) { // write code here int total = 10, res = 10; for(int i=0; i<fruit.length; i++){ total+=fruit[i]; res = Math.max(res,total); } return res; } }