题解 | 连续子链表最大和
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @return int整型
*/
int FindGreatestSumOfSubArray(struct ListNode* head)
{
int summax = head->val;
int sum = head->val;
struct ListNode* cur = head->next;
while (cur)
{
if(sum>0)
sum+=cur->val;
else
sum=cur->val;
if(sum>summax)
summax=sum;
cur = cur->next;
}
return summax;
}
查看14道真题和解析