Skip to content

Commit f46f265

Browse files
committed
solve problem
1 parent a883d95 commit f46f265

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

maximum-subarray/delight010.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
func maxSubArray(_ nums: [Int]) -> Int {
3+
var maxSum = nums[0]
4+
var maxEndingHere = nums[0]
5+
for i in 1..<nums.count {
6+
maxEndingHere = max(nums[i], maxEndingHere + nums[i])
7+
maxSum = max(maxSum, maxEndingHere)
8+
}
9+
return maxSum
10+
}
11+
}
12+

0 commit comments

Comments
 (0)