Last active
August 7, 2019 13:38
-
-
Save sahajre/f458a61b6e15d27d740a142fa445c1e7 to your computer and use it in GitHub Desktop.
This file contains 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 mspN2(n []int) (maxSum, mi, mj int) { | |
l := len(n) | |
if l == 0 { | |
return -1, -1, -1 | |
} | |
maxSum = n[0] | |
for i := 0; i < l; i++ { | |
sum := 0 | |
for k := i; k < l; k++ { | |
sum += n[k] | |
if sum > maxSum { | |
maxSum = sum | |
mi = i | |
mj = k | |
} | |
if sum == maxSum { | |
mj = k | |
} | |
} | |
} | |
return maxSum, mi, mj | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment