题解 | #用两个栈实现队列#

连续子数组的最大和

http://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484

using System;
using System.Collections.Generic;


class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param array int整型一维数组 
     * @return int整型
     */
    public int FindGreatestSumOfSubArray (List<int> array) {
        // write code here
//         if(array.Count == 0){
//             return 0;
//         }
        List<int> dp = new List<int>(array.Count);
        dp.Add(array[0]);
        int max = dp[0];
        for(int i=1; i<array.Count; i++){
            dp.Add(Math.Max(dp[i-1]+array[i], array[i]));
            max = Math.Max(max, dp[i]);
        }
        return max;
    }
}
全部评论

相关推荐

12-15 14:16
门头沟学院 Java
回家当保安:发offer的时候会背调学信网,最好不要这样。 “27届 ”和“28届以下 ”公司招聘的预期是不一样的。
实习简历求拷打
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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