https://leetcode-cn.com/problems/maximum-subarray/
func maxSubArray(_ nums: [Int]) -> Int {
var curMax = nums[0]
var sum = nums[0]
for idx in stride(from: 1, to: nums.count, by: 1) {
curMax = max(nums[idx], curMax + nums[idx])
sum = max(curMax, sum)
}
return sum
}
网友评论