MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / MaxSubArraySum

Function MaxSubArraySum

dynamic/maxsubarraysum.go:12–22  ·  view source on GitHub ↗

MaxSubArraySum returns the sum of the maximum subarray in the input array

(nums []int)

Source from the content-addressed store, hash-verified

10
11// MaxSubArraySum returns the sum of the maximum subarray in the input array
12func MaxSubArraySum(nums []int) int {
13 maxSum := nums[0]
14 currentSum := nums[0]
15
16 for i := 1; i < len(nums); i++ {
17 currentSum = max.Int(nums[i], currentSum+nums[i])
18 maxSum = max.Int(maxSum, currentSum)
19 }
20
21 return maxSum
22}

Callers 1

TestMaxSubArraySumFunction · 0.92

Calls 1

IntFunction · 0.92

Tested by 1

TestMaxSubArraySumFunction · 0.74