Skip to content

Instantly share code, notes, and snippets.

@leftrk
Last active December 7, 2018 08:30
Show Gist options
  • Select an option

  • Save leftrk/be35137c0e68dfd908cd15d94c156a81 to your computer and use it in GitHub Desktop.

Select an option

Save leftrk/be35137c0e68dfd908cd15d94c156a81 to your computer and use it in GitHub Desktop.
最大相连子序列和的 O(n^2) 算法
/**
* @param a
* @return maxsum
* @brief 最大相连子序列和的 O(n^2) 算法
*/
int maxSubSum2(const vector<int> &a) {
int maxSum = 0;
for (int i = 0; i < a.size(); ++i) {
int thisSum = 0;
for (int j = i; j < a.size(); ++j) {
thisSum += a[j];
if (thisSum > maxSum)
maxSum = thisSum;
}
}
return maxSum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment