Skip to content

Instantly share code, notes, and snippets.

@ApsarasX
Created March 9, 2018 13:52
Show Gist options
  • Save ApsarasX/d16f60e947b66f379dfaaaebdb0d0ce5 to your computer and use it in GitHub Desktop.
Save ApsarasX/d16f60e947b66f379dfaaaebdb0d0ce5 to your computer and use it in GitHub Desktop.
int maxSubSequence(int arr[], int n)
{
int sum = 0, maxSum = 0;
for (int i = 0; i < n; i++)
{
sum += arr[i];
if (sum > maxSum)
maxSum = sum;
else if (sum < 0)
{
sum = 0;
}
}
return maxSum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment