Skip to content

Commit

Permalink
update self._v without loop in init()
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyod committed Sep 5, 2024
1 parent 67e98c9 commit 51a4778
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions fenwick/fenwick.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ def __setitem__(self, idx, value):
def init(self, frequencies):
"""Initialize in O(n) with specified frequencies."""
if len(frequencies) != self._n:
raise ValueError("Number of frequencies must match size of tree.")
for idx in _range(self._n):
self._v[idx] = frequencies[idx]
raise ValueError("Length of frequencies must match length of FenwickTree.")
self._v = list(frequencies)
for idx in _range(1, self._n + 1):
parent_idx = idx + (idx & -idx) # parent in update tree
if parent_idx <= self._n:
Expand Down

0 comments on commit 51a4778

Please sign in to comment.