考察知识点:数组、前缀和、差分数组
题目分析:
题目给出的序列是一个差分数组。对差分数组求前缀和就能得到原序列。然后维护一个最大值即可。
所用编程语言:C++
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param fruit int整型vector * @return int整型 */ int mostFruitTree(vector<int>& fruit) { // write code here int size = fruit.size(); int value = 10; int maxFruit = 10; for (auto &num: fruit) { value += num; maxFruit = max(maxFruit, value); } return maxFruit; } };