Maximum subsequence sum

简介:

This is a very famous problem from programming peals

Given an array of integers, return the maximum 
subsequence sum of the array, if the maximus sum
less than 0, return 0
Example
1, 2, -6, 3, -2, 4, -1, 3, 2, -4
return 9
3 + -2 + 4 + -1 + 3 + 2 = 9

 

Code

 

or more concise

Code

 

 本文转自zdd博客园博客,原文链接:http://www.cnblogs.com/graphics/archive/2009/06/09/1499815.html,如需转载请自行联系原作者

相关文章
|
人工智能 算法
1305:Maximum sum
1305:Maximum sum
LeetCode 209. Minimum Size Subarray Sum
给定一个含有 n 个正整数的数组和一个正整数 s ,找出该数组中满足其和 ≥ s 的长度最小的连续子数组。如果不存在符合条件的连续子数组,返回 0。
124 0
LeetCode 209. Minimum Size Subarray Sum
Maximum Subsequence Sum
最大连续子列和问题,在此给出题解 (浙大PTA https://pintia.cn/problem-sets/16/problems/665)
LeetCode之Sum of Two Integers
LeetCode之Sum of Two Integers
124 0
LeetCode之Max Consecutive Ones
LeetCode之Max Consecutive Ones
137 0
1104. Sum of Number Segments (20) consecutive subsequence 每个数出现的次数
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence.
971 0
|
人工智能 机器学习/深度学习
1007. Maximum Subsequence Sum (25)
简析:求最大子列和,并输出其首末元素。在线处理,关键在于求首末元素。 本题囧,16年9月做出来过,现在15分钟只能拿到22分,有一个测试点过不了。
978 0
[LeetCode] Sum of Two Integers
The code is as follows. public class Solution { public int getSum(int a, int b) { return b == 0 ? a : getSum(a ^ b, (a & b)
1123 0