aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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()