#!/usr/bin/env python3

__author__ = 'Wei Mu'

class Solution:
    def maxSubArray(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums) == 1:
            return(nums[0])
        
        pointer = 0
        res = nums[0]
        temp = nums[0]
        
        while pointer <len(nums)-1:
            pointer += 1
            
            if temp <= 0:
                temp = nums[pointer]
            else:
                temp = temp + nums[pointer]
            
            if temp > res:
                res = temp
            
            if temp < 0 and pointer < len(nums):
                temp = 0
                
        return res
