2022-03-27 20:37:52 +08:00
< p > Given an array < code > nums< / code > and an integer < code > target< / code > , return < em > the maximum number of < strong > non-empty< / strong > < strong > non-overlapping< / strong > subarrays such that the sum of values in each subarray is equal to< / em > < code > target< / code > .< / p >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 20:37:52 +08:00
< pre >
< strong > Input:< / strong > nums = [1,1,1,1,1], target = 2
< strong > Output:< / strong > 2
< strong > Explanation:< / strong > There are 2 non-overlapping subarrays [< strong > 1,1< / strong > ,1,< strong > 1,1< / strong > ] with sum equals to target(2).
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-03-27 20:37:52 +08:00
< pre >
< strong > Input:< / strong > nums = [-1,3,5,1,4,2,-9], target = 6
< strong > Output:< / strong > 2
< strong > Explanation:< / strong > 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.
< / pre >
< p > < / 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 >
< li > < code > 0 < = target < = 10< sup > 6< / sup > < / code > < / li >
< / ul >