Handle empty input case in Segment Tree build process (#8718)

This commit is contained in:
roger-sato 2023-08-01 03:46:30 +09:00 committed by GitHub
parent 629eb86ce0
commit 0b0214c42f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,8 @@ class SegmentTree:
self.st = [0] * (
4 * self.N
) # approximate the overall size of segment tree with array N
self.build(1, 0, self.N - 1)
if self.N:
self.build(1, 0, self.N - 1)
def left(self, idx):
return idx * 2