码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode1277

时间:2019-12-01 13:35:53      阅读:65      评论:0      收藏:0      [点我收藏+]

标签:list   ret   http   elf   tar   class   etc   min   log   

 1 class Solution:
 2     def countSquares(self, matrix: List[List[int]]) -> int:
 3         m = len(matrix)
 4         if m == 0:
 5             return 0
 6         n = len(matrix[0])
 7         dp = [[0 for _ in range(n+1)]for _ in range(m+1)]
 8         res = 0
 9         for i in range(m):
10             for j in range(n):
11                 if matrix[i][j] == 1:
12                     dp[i+1][j+1] = min(min(dp[i][j+1],dp[i+1][j]),dp[i][j]) + 1
13                     res += dp[i+1][j+1]
14         return res

和题目leetcode221思路一样,只有第13行和14行不同。

leetcode1277

标签:list   ret   http   elf   tar   class   etc   min   log   

原文地址:https://www.cnblogs.com/asenyang/p/11965584.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!