Class Solution
java.lang.Object
g0001_0100.s0053_maximum_subarray.Solution
53 - Maximum Subarray.<p>Easy</p>
<p>Given an integer array <code>nums</code>, find the contiguous subarray (containing at least one number) which has the largest sum and return <em>its sum</em>.</p>
<p>A <strong>subarray</strong> is a <strong>contiguous</strong> part of an array.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> [4,-1,2,1] has the largest sum = 6.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [5,4,-1,7,8]</p>
<p><strong>Output:</strong> 23</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>
</ul>
<p><strong>Follow up:</strong> If you have figured out the <code>O(n)</code> solution, try coding another solution using the <strong>divide and conquer</strong> approach, which is more subtle.</p>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxSubArray
public int maxSubArray(int[] nums)
-