aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-01-19 16:14:06 +0000
committerterminaldweller <devi@terminaldweller.com>2024-01-19 16:14:06 +0000
commit02d3b291f5b09c809b28fb2727e1d11733fec734 (patch)
tree0d31fff50659d878ce8304cce0200f345448ffe3
parent70 (diff)
downloadleetcode-02d3b291f5b09c809b28fb2727e1d11733fec734.tar.gz
leetcode-02d3b291f5b09c809b28fb2727e1d11733fec734.zip
931 py
-rwxr-xr-x931/main.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/931/main.py b/931/main.py
new file mode 100755
index 0000000..67dac11
--- /dev/null
+++ b/931/main.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+
+import typing
+
+
+class Solution:
+ def minFallingPathSum(self, matrix: typing.List[typing.List[int]]) -> int:
+ for i in range(1, len(matrix)):
+ for j in range(len(matrix[i])):
+ matrix[i][j] = (
+ min(
+ matrix[i - 1][j],
+ matrix[i - 1][max(0, j - 1)],
+ matrix[i - 1][min(len(matrix[i]) - 1, j + 1)],
+ )
+ + matrix[i][j]
+ )
+
+ return min(matrix[-1])
+
+
+def main():
+ solution = Solution()
+ print(solution.minFallingPathSum([[2, 1, 3], [6, 5, 4], [7, 8, 9]]))
+
+
+if __name__ == "__main__":
+ main()