题解 | #连续最大和#

连续最大和

http://www.nowcoder.com/practice/5a304c109a544aef9b583dce23f5f5db

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int t = sc.nextInt();
        int s = t;
        if(t < 0) {
            t = 0;
        }
        for(int i = 1; i < N; i++) {
            t += sc.nextInt();
            s = Math.max(s, t);
            if(t < 0) {
                t = 0;
            }
        }
        System.out.println(s);
    }
}
全部评论

相关推荐

希望被捞的猫头鹰很理智:大概率待遇低怕硕士跑路
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

更多
牛客网
牛客企业服务