题解 | #连续子链表最大和#

连续子链表最大和

http://www.nowcoder.com/practice/650b68dfa69d492d92645aecd7da9b21

import java.util.*;

public class Solution {

    public int FindGreatestSumOfSubArray (ListNode head) {
        // write code here
        int cur=-10001, max=-10001;
        ListNode temp= head;
        while(temp!=null){
            cur = Math.max(cur+temp.val,temp.val);
            max = Math.max(cur,max);
            temp = temp.next;
        }
        return max;
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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