介绍
考虑一个非空整数列表L。甲零和切片的大号是的连续子序列大号其总和等于0。例如,[1,-3,2]是零和切片[-2,4,1,-3,2,2 ,-1,-1],但[2,2]不是(因为它的总和不为0),[4,-3,-1]也不是(因为它不连续)。
的零和切片的集合大号是零和盖的大号如果每一个元素属于切片中的至少一个。例如:
L = [-2, 4, 1, -3, 2, 2, -1, -1]
A = [-2, 4, 1, -3]
B = [1, -3, 2]
C = [2, -1, -1]
三个零和切片A,B和C构成L的零和覆盖。同一切片的多个副本可以出现在零和封面中,如下所示:
L = [2, -1, -1, -1, 2, -1, -1]
A = [2, -1, -1]
B = [-1, -1, 2]
C = [2, -1, -1]
当然,并非所有列表都具有零和保险;例如[2,-1](每个切片的总和都不为零)和[2,2,-1,-1,-1,0,1](最左边的2不是零和切片的一部分)。
任务
您的输入是采用任何合理格式的非空整数列表L。如果L的总和为零,则输出为真实值,否则为假值。
您可以编写完整的程序或函数,最低的字节数为准。
测试用例
[-1] -> False
[2,-1] -> False
[2,2,-1,-1,0,1] -> False
[2,-2,1,2,-2,-2,4] -> False
[3,-5,-2,0,-3,-2,-1,-2,0,-2] -> False
[-2,6,3,-3,-3,-3,1,2,2,-2,-5,1] -> False
[5,-8,2,-1,-7,-4,4,1,-8,2,-1,-3,-3,-3,5,1] -> False
[-8,-8,4,1,3,10,9,-11,4,4,10,-2,-3,4,-10,-3,-5,0,6,9,7,-5,-3,-3] -> False
[10,8,6,-4,-2,-10,1,1,-5,-11,-3,4,11,6,-3,-4,-3,-9,-11,-12,-4,7,-10,-4] -> False
[0] -> True
[4,-2,-2] -> True
[2,2,-3,1,-2,3,1] -> True
[5,-3,-1,-2,1,5,-4] -> True
[2,-1,-1,-1,2,-1,-1] -> True
[-2,4,1,-3,2,2,-1,-1] -> True
[-4,-1,-1,6,3,6,-5,1,-5,-4,5,3] -> True
[-11,8,-2,-6,2,-12,5,3,-7,4,-7,7,12,-1,-1,6,-7,-4,-5,-12,9,5,6,-3] -> True
[4,-9,12,12,-11,-11,9,-4,8,5,-10,-6,2,-9,10,-11,-9,-2,8,4,-11,7,12,-5] -> True
[2,2,-1,-1,0,1] -> False
是真实的,因为两个slice [2,-1,-1]
和都[-1,0,1]
加零并且它们的所有元素都在原始列表中?