Skip to content

Commit cdd1826

Browse files
committed
Solution Maximum subarray
1 parent a3e09bd commit cdd1826

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

maximum-subarray/doitduri.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 currentSum = nums[0]
4+
var maxSum = nums[0]
5+
6+
for i in 1..<nums.count {
7+
currentSum = max(nums[i], currentSum + nums[i])
8+
maxSum = max(maxSum, currentSum)
9+
}
10+
return maxSum
11+
}
12+
}

0 commit comments

Comments
 (0)