Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/dsa/various.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def string_concat(n):


def matrix_sum(matrix: list[list[int]]) -> list[int]:
return [sum(matrix[i]) for i in range(len(matrix)) if sum(matrix[i]) > 0]
# Compute the row sum once, and include if > 0
return [row_sum for row in matrix if (row_sum := sum(row)) > 0]


def graph_traversal(graph: dict[int, dict[int]], node: int) -> dict[int]:
Expand Down