Class Solution
-
- All Implemented Interfaces:
public final class Solution1546 - Maximum Number of Non-Overlapping Subarrays With Sum Equals Target.
Medium
Given an array
numsand an integertarget, return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal totarget.Example 1:
Input: nums = 1,1,1,1,1, target = 2
Output: 2
Explanation: There are 2 non-overlapping subarrays **1,1** ,1, **1,1** with sum equals to target(2).
Example 2:
Input: nums = -1,3,5,1,4,2,-9, target = 6
Output: 2
Explanation: There are 3 subarrays with sum equal to 6. (5,1, 4,2, 3,5,1,4,2,-9) but only the first 2 are non-overlapping.
Constraints:
<code>1 <= nums.length <= 10<sup>5</sup></code>
<code>-10<sup>4</sup><= numsi<= 10<sup>4</sup></code>
<code>0 <= target <= 10<sup>6</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegermaxNonOverlapping(IntArray nums, Integer target)-
-
Method Detail
-
maxNonOverlapping
final Integer maxNonOverlapping(IntArray nums, Integer target)
-
-
-
-