title: Can anyone explain this "Maxium Subarray" problem?
body: <p>I once saw this coding question online..</p>
  
  <blockquote>
    <p>Given an integer array nums, find the contiguous subarray (containing
    at least one number) which has the largest sum and return its sum. <br/><br/>
    Example:  </p>
  </blockquote>
  
  <pre><code>Input: [-2,1,-3,4,-1,2,1,-5,4],
  Output: 6
  Explanation: [4,-1,2,1] has the largest sum = 6.
  </code></pre>
  
  <p>...and got a solution from a leetcode user...</p>
  
  <pre><code>def maxSubArray(self, nums: List[int]) -&gt; int:
      sumVal = 0
      ret = 0
      for i in nums:
          sumVal = max(0, sumVal) + i
          ret = max(ret, sumVal)
      return max(nums) if ret == 0 else ret
  </code></pre>
  
  <p>Though I don't know how it works even after some "debugging".</p>
  
  <p>Can you explain it?</p>