Skip to content

Commit de5705c

Browse files
Update prefix_sum.py
1 parent 6bee841 commit de5705c

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

data_structures/arrays/prefix_sum.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, array: list[int]) -> None:
2020

2121
def get_sum(self, start: int, end: int) -> int:
2222
"""
23-
The function returns the sum of array from the start to the end indexes
23+
The function returns the sum of array from the start to the end indexes.
2424
Runtime : O(1)
2525
Space: O(1)
2626
@@ -41,11 +41,10 @@ def get_sum(self, start: int, end: int) -> int:
4141
if start < 0 or end >= len(self.prefix_sum) or start > end:
4242
raise ValueError("Invalid range specified.")
4343

44-
return (
45-
self.prefix_sum[end]
46-
if start == 0
47-
else self.prefix_sum[end] - self.prefix_sum[start - 1]
48-
)
44+
if start == 0:
45+
return self.prefix_sum[end]
46+
47+
return self.prefix_sum[end] - self.prefix_sum[start - 1]
4948

5049
def contains_sum(self, target_sum: int) -> bool:
5150
"""

0 commit comments

Comments
 (0)