题解 | #连续子链表最大和#
连续子链表最大和
https://www.nowcoder.com/practice/650b68dfa69d492d92645aecd7da9b21
package main
import . "nc_tools"
/*
* type ListNode struct{
* Val int
* Next *ListNode
* }
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @return int整型
*/
func FindGreatestSumOfSubArray( head *ListNode ) int {
// write code here
sum, max := head.Val, head.Val
head = head.Next
for head != nil {
sum += head.Val
if sum < head.Val {
sum = head.Val
}
if sum > max {
max = sum
}
head =head.Next
}
return max
}
