Last active
January 11, 2016 02:17
-
-
Save thanhnguyentang/70576db10faad3603099 to your computer and use it in GitHub Desktop.
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
| MAXIMUM-SUBARRAY(A, low, high) | |
| sum = A[low] | |
| left_index = low | |
| right_index = low | |
| right_sum = A[low] | |
| start_index = low | |
| for i = low+1 to high | |
| if right_sum > 0 | |
| right_sum = right_sum + A[i] | |
| else | |
| right_sum = A[i] | |
| start_index = i | |
| if sum < right_sum | |
| sum = right_sum | |
| right_index = i | |
| left_index = start_index | |
| return left_index, right_index, sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment