maximum_subarray

  • 2022-12-14
  • 浏览 (524)

maximum_subarray.go 源码

package main

import "math"

//最大子序和

func maxSubArray(nums []int) int {
	res, max := nums[0], nums[0]
	for i := 1; i < len(nums); i++ {
		max = int(math.Max(float64(nums[i]), float64(max+nums[i])))
		res = int(math.Max(float64(res), float64(max)))
	}
	return res
}

你可能感兴趣的文章

coin_change

decode_ways

delete_operation_two_strings

0  赞