O(n) solution in Swift


#1

func maxSubArray(_ A: [Int]) -> Int {
var curMaxSum = A[0]
var globalMaxSum = curMaxSum
for i in 1…<A.count {
curMaxSum = max(A[i], A[i] + curMaxSum)
globalMaxSum = max(curMaxSum, globalMaxSum)
}
return globalMaxSum
}