Created
August 7, 2019 12:10
-
-
Save sahajre/f5b8b6b49c56b26511bd60945d2df3a7 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
| package msp | |
| func mspN1(n []int) (maxSum, mi, mj int) { | |
| l := len(n) | |
| if l == 0 { | |
| return -1, -1, -1 | |
| } | |
| maxSum = n[0] | |
| sum := n[0] | |
| i := 0 | |
| for j := 1; j < l; j++ { | |
| sum += n[j] | |
| if sum > maxSum { | |
| maxSum = sum | |
| mi = i | |
| mj = j | |
| } else if sum < 0 { | |
| i = j + 1 | |
| sum = 0 | |
| } | |
| } | |
| return maxSum, mi, mj | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment