小编cod*_*_it的帖子

如果可以删除任何一个元素,则查找是否可以将数组分为相等和的两个子数组

给定一个数字数组,查找是否有办法从数组中删除/移除一个数字并在数组中进行一个分区(将数组划分为两个子数组),使得 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)

arrays algorithm sub-array

5
推荐指数
1
解决办法
180
查看次数

标签 统计

algorithm ×1

arrays ×1

sub-array ×1