Skip to content

Commit 19186a6

Browse files
authored
Apply suggestions from code review
1 parent b2a6a74 commit 19186a6

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

matrix/median_matrix.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@ def median(matrix: list[list[int]]) -> int:
2222
>>> median(matrix)
2323
3
2424
"""
25-
# Flatten the matrix into a 1D list
26-
linear = [num for row in matrix for num in row]
27-
28-
# Sort the 1D list
29-
linear.sort()
25+
# Flatten the matrix into a sorted 1D list
26+
linear = sorted(num for row in matrix for num in row)
3027

3128
# Calculate the middle index
32-
mid = (0 + len(linear) - 1) // 2
29+
mid = (len(linear) - 1) // 2
3330

3431
# Return the median
3532
return linear[mid]

0 commit comments

Comments
 (0)