Class Solution
java.lang.Object
g0901_1000.s0918_maximum_sum_circular_subarray.Solution
918 - Maximum Sum Circular Subarray.<p>Medium</p>
<p>Given a <strong>circular integer array</strong> <code>nums</code> of length <code>n</code>, return <em>the maximum possible sum of a non-empty <strong>subarray</strong> of</em> <code>nums</code>.</p>
<p>A <strong>circular array</strong> means the end of the array connects to the beginning of the array. Formally, the next element of <code>nums[i]</code> is <code>nums[(i + 1) % n]</code> and the previous element of <code>nums[i]</code> is <code>nums[(i - 1 + n) % n]</code>.</p>
<p>A <strong>subarray</strong> may only include each element of the fixed buffer <code>nums</code> at most once. Formally, for a subarray <code>nums[i], nums[i + 1], ..., nums[j]</code>, there does not exist <code>i <= k1</code>, <code>k2 <= j</code> with <code>k1 % n == k2 % n</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,-2,3,-2]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> Subarray [3] has maximum sum 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [5,-3,5]</p>
<p><strong>Output:</strong> 10</p>
<p><strong>Explanation:</strong> Subarray [5,5] has maximum sum 5 + 5 = 10.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [-3,-2,-3]</p>
<p><strong>Output:</strong> -2</p>
<p><strong>Explanation:</strong> Subarray [-2] has maximum sum -2.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>1 <= n <= 3 * 10<sup>4</sup></code></li>
<li><code>-3 * 10<sup>4</sup> <= nums[i] <= 3 * 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxSubarraySumCircular
public int maxSubarraySumCircular(int[] nums)
-