53. Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
A subarray is a contiguous part of an array.
Kanade’s Algorithm
In an arbitary position i, the maximum subarray sum equals nums[i] or previous maximum subarray sum + nums[i]. This is a Mathematical Induction (MI) problem. Traversal the array nums, we can find the maximum subarray sum.
1 | class Solution { |