Compare commits

...

2 Commits

Author SHA1 Message Date
pre-commit-ci[bot]
621a09f074 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-10-05 13:45:06 +00:00
Anubhav Joshi
204c38836b
Update diagonal_traversal.py to adhere ruff suggestions 2024-10-05 19:12:43 +05:30

View File

@ -45,14 +45,13 @@ def find_diagonal_order(mat: list[list[int]]) -> list[int]:
else: # move up diagonally
row -= 1
col += 1
else: # moving down
if row == m - 1: # hit the bottom boundary
col += 1
elif col == 0: # hit the left boundary
row += 1
else: # move down diagonally
row += 1
col -= 1
elif row == m - 1: # hit the bottom boundary
col += 1
elif col == 0: # hit the left boundary
row += 1
elif col > 0 and row < m - 1: # move down diagonally
row += 1
col -= 1
return result