Last active
December 7, 2018 08:30
-
-
Save leftrk/be35137c0e68dfd908cd15d94c156a81 to your computer and use it in GitHub Desktop.
最大相连子序列和的 O(n^2) 算法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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