给定一个数字数组,查找是否有办法从数组中删除/移除一个数字并在数组中进行一个分区(将数组划分为两个子数组),使得 subarray1 中的元素总和等于 subarray2 中元素的总和.
A subarray is a contiguous part of array.
Array [1, 2, 3, 4] has (1), (1,2), (2,3,4),(1,2,3,4) etc.. as its subarrays but not (1,3) , (2,4) , (1,3,4), etc..
Run Code Online (Sandbox Code Playgroud)
现在让我们考虑一个例子:-
(Follow 0-based indexing )
Array[] = [ 6, 2, 2, 1, 3 ]
Possible solutions
Delete Array[0] => updated array: - [ 2,2,1,3 ]
Possible partition : - [2,2] and [3,1] where (2+2) = (3+1) = 4
or
Delete Array[1] => updated array: - [ …Run Code Online (Sandbox Code Playgroud)