当前位置:网站首页>leetcode:221. Maximum square [essence of DP state transition]
leetcode:221. Maximum square [essence of DP state transition]
2022-07-05 13:01:00 【White speed Dragon King's review】

analysis
dp[i][j] Said to (i, j) Is the largest square side length in the lower right corner
The first row and the first column are special
Other words need to consider the essence formula :
dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
It's the essence of the world
ac code
class Solution:
def maximalSquare(self, matrix: List[List[str]]) -> int:
ans = 0
# dp[i][j] Said to (i, j) It is the largest collection in the lower right corner 1 Square area
m, n = len(matrix), len(matrix[0])
dp = [[0] * n for _ in range(m)]
for i in range(m):
for j in range(n):
if matrix[i][j] == '1':
if i == 0 or j == 0:
dp[i][j] = 1
else:
# quintessence
dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
ans = max(ans, dp[i][j] * dp[i][j])
return ans
summary
dp tricks
About finding one that's all 1 The largest square of
边栏推荐
- 函数传递参数小案例
- Introduction to sap ui5 flexiblecolumnlayout control
- Notes for preparation of information system project manager --- information knowledge
- Comprehensive upgrade of Taobao short video photosynthetic platform
- RHCSA1
- The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
- 简单上手的页面请求和解析案例
- Research: data security tools cannot resist blackmail software in 60% of cases
- Alibaba cloud SLB load balancing product basic concept and purchase process
- Detailed explanation of navigation component of openharmony application development
猜你喜欢

Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue

Get to know linkerd project for the first time

Didi open source Delta: AI developers can easily train natural language models

SAP SEGW 事物码里的导航属性(Navigation Property) 和 EntitySet 使用方法

Compilation principle reading notes (1/12)

Discussion on error messages and API versions of SAP ui5 getsaplogonlanguage is not a function

SAP ui5 objectpagelayout control usage sharing

Distance measuring sensor chip 4530a used in home intelligent lighting

百日完成国产数据库opengausss的开源任务--openGuass极简版3.0.0安装教程

我在滴滴做开源
随机推荐
Wechat enterprise payment to change access, open quickly
Insmod prompt invalid module format
《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
Natural language processing series (I) introduction overview
RHCAS6
155. Minimum stack
SAP UI5 FlexibleColumnLayout 控件介绍
MySQL splits strings for conditional queries
Le rapport de recherche sur l'analyse matricielle de la Force des fournisseurs de RPA dans le secteur bancaire chinois en 2022 a été officiellement lancé.
SAP UI5 视图里的 OverflowToolbar 控件
Concurrent performance test of SAP Spartacus with JMeter
##无监控,不运维,以下是监控里常用的脚本监控
Transactions on December 23, 2021
Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
Notes for preparation of information system project manager --- information knowledge
你的下一台电脑何必是电脑,探索不一样的远程操作
自然语言处理系列(一)入门概述
【Nacos云原生】阅读源码第一步,本地启动Nacos
Run, open circuit