My intuitive python solution


  • 3
    B
    def maxSubArray(self, nums):
        T = nums[0]
        maxsub = T
        for i in nums[1:]:
            T += i
            if i > T:
                T = i
            if T > maxsub:
                maxsub = T
        return maxsub

  • 0

    We have the same solution idea! :)

        def maxSubArray(self, nums):
            maxn=nums[0]
            i=1
            max1=maxn
            while i<len(nums):
                if maxn+nums[i]<nums[i]:
                    maxn=nums[i]
                else:
                    maxn=maxn+nums[i]
                i=i+1
                if max1<maxn:
                    max1=maxn
            return max1

  • 0

    i > T is pretty intuitive @


  • 0
    R

    This is by far the best solution so far. I came to the same solution as well!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.