下面来介绍一道LeetCode上的题:
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
For example, given the array [-2,1,-3,4,-1,2,1,-5,4],
the contiguous subarray [4,-1,2,1] has the largest sum = 6.
算法一:暴力枚举法,算法复杂度为O(N三次方)
int maxsequence1(int A[], int N)
{
int ThisSum , MaxSum=0;
int i, j, k;
for (i = 0; i <= N; i++) {
for (j = i; j <= N; j++) {
ThisSum =