Skip to content

Commit e47c187

Browse files
authored
Update longest-increasing-path-in-a-matrix.py
1 parent ae6fc33 commit e47c187

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Python/longest-increasing-path-in-a-matrix.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ def longestIncreasingPath(self, matrix):
1010
"""
1111
directions = [(0, -1), (0, 1), (-1, 0), (1, 0)]
1212

13+
if not matrix:
14+
return 0
15+
1316
in_degree = [[0]*len(matrix[0]) for _ in xrange(len(matrix))]
1417
for i in xrange(len(matrix)):
1518
for j in xrange(len(matrix[0])):
@@ -66,6 +69,8 @@ def longestpath(matrix, i, j, max_lengths):
6669
max_lengths[i][j] = max_depth + 1
6770
return max_lengths[i][j]
6871

72+
if not matrix:
73+
return 0
6974
result = 0
7075
max_lengths = [[0 for _ in xrange(len(matrix[0]))] for _ in xrange(len(matrix))]
7176
for i in xrange(len(matrix)):

0 commit comments

Comments
 (0)