You are given an integer array which contains positive integers, zero and negetive integers
count how many consecutive sequences in this array make a sum of 0.
exmaple
int[] a = {4, -1, 2, 1, -2, -1, 5, 0} ;
The result is 2
-1, 2, 1, -2, makes a sum of 0
2, 1, -2, -1, makes a sum of 0
0 makes a sum of 0
consider a consecutive sequence in array a, say xi, ... xj, if xi + ... + xj = 0, then x0 + .. + x(i-1) = x0 + .. + xj
so we can compute all the prefix sum of array a, and see whether there are equal elements among these sum
if there is, then there must be some consecutive sequence, makes sum of 0
![](https://ucc.alicdn.com/uywxdjoxsp63u/developer-article385608/20241017/b6fcfa4d5daf4e14b44b51e3d3861794.gif)
本文转自zdd博客园博客,原文链接:http://www.cnblogs.com/graphics/archive/2009/06/09/1499768.html,如需转载请自行联系原作者