221.Maximal-Square

221. Maximal Square

题目地址

https://leetcode.com/problems/maximal-square/

题目描述

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.

Example:

Input: 
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0

Output: 4

代码

Approach #1 Brute Force

Time complexity : O((m*n)^2)

Approach #2 Dynamic Programming

Approach #3 Better Dynamic Programming

dp[j] = min(dp[j - 1], dp[j], prev)

Last updated

Was this helpful?