Leetcde-931. Minimum Falling Path Sum

Original link: https://leetcode.com/problems/minimum-falling-path-sum/

For elements in the second line and below, we can search the upper two or three elements and add the minimum value.
Boundary condition: elements in the most left and the most right. They can only search for two elements.

Code:

class Solution(object):
    def minFallingPathSum(self, A):
        """
        :type A: List[List[int]]
        :rtype: int
        """
        
        for r in range(1, len(A)):
            
            A[r][0] += min(A[r-1][0], A[r-1][1])
            
            for c in range(1, len(A[r]) - 1):
                
                A[r][c] += min(A[r-1][c-1:c+2])

            A[r][-1] += min(A[r-1][-2], A[r-1][-1])
        
        return min(A[-1])
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.5.9) 2025-03-29 23:30:44.927 INFO 10080 --- [ main] com.example.SpringbootApplication : Starting SpringbootApplication using Java 1.8.0_341 on DESKTOP-EUNUR1G with PID 10080 (D:\毕业设计\manager\springboot\target\classes started by DELL in D:\毕业设计\manager) 2025-03-29 23:30:44.929 INFO 10080 --- [ main] com.example.SpringbootApplication : No active profile set, falling back to default profiles: default 2025-03-29 23:30:45.709 INFO 10080 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9090 (http) 2025-03-29 23:30:45.716 INFO 10080 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2025-03-29 23:30:45.716 INFO 10080 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56] 2025-03-29 23:30:45.800 INFO 10080 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2025-03-29 23:30:45.800 INFO 10080 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 836 ms Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter. Parsed mapper file: 'file [D:\毕业设计\manager\springboot\target\classes\mapper\AdminMapper.xml]' Parsed mapper file: 'file [D:\毕业设计\manager\springboot\target\classes\mapper\NoticeMapper.xml]' ,------. ,--. ,--. ,--. | .--. ' ,--,--. ,---. ,---. | '--' | ,---. | | ,---. ,---. ,--.--. | '--' | ' ,-. | | .-. | | .-. : | .--. | | .-. : | | | .-. | | .-. : | .--' | | -
03-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值