题解 | 小猪摘水果

小猪摘水果

https://www.nowcoder.com/practice/fdb76b9170dc4e689a7eceee97159d96

  1. 前缀和

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;
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务