go语言刷leetcode - 53 Maximum Subarray
package main import ( "fmt" "math" ) func maxSubArray(nums []int) int { var largestSum float64 = -math.MaxFloat64 var currentSum float64 = -math.MaxFloat64 for i := 0; i < len(nums); i++ { currentSum = math.Max(currentSum+float64(nums[i]), float64(nums[i])) largestSum = math.Max(largestSum, currentSum) } return int(largestSum) } func main() { fmt.Println(maxSubArray([]int{-1})) }