Skip to content

Commit 79eefce

Browse files
committed
add sub array with zero sum code solution
1 parent 4d93a0d commit 79eefce

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Array/Python/ArrayPrefix/SubArrayWithZero/Readme.md

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def subArrayWithZero(arr):
2+
3+
prefixSum = arr[0]
4+
prefixMap = {}
5+
prefixMap[prefixSum] = 1
6+
7+
for i in range(1, len(arr)):
8+
prefixSum +=arr[i]
9+
if prefixMap.get(prefixSum) == 1:
10+
return True
11+
12+
if prefixSum == 0:
13+
return True
14+
15+
prefixMap[prefixSum] = 1
16+
17+
18+
return False
19+
20+
arr = [-3, 2, 3, 1, 6]
21+
print(subArrayWithZero(arr))

0 commit comments

Comments
 (0)