Skip to content

Commit 438c795

Browse files
committed
Handle empty input case in Segment Tree build process
1 parent c1b3ea5 commit 438c795

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

data_structures/binary_tree/segment_tree.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ def __init__(self, a):
77
self.st = [0] * (
88
4 * self.N
99
) # approximate the overall size of segment tree with array N
10-
self.build(1, 0, self.N - 1)
10+
if self.N:
11+
self.build(1, 0, self.N - 1)
1112

1213
def left(self, idx):
1314
return idx * 2

0 commit comments

Comments
 (0)