Post

leetcode(리트코드)221-Maximal Square

leetcode 221 - Maximal Square 문제입니다.

1. 문제

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


2. Input , Output


3. 분류 및 난이도

Medium 난이도 문제입니다.
leetcode Top 100 Liked 문제입니다.


4. 문제 해석

  • 1로 이루어진 정사각의 넓이가 가장 큰 것의 넓이를 리턴하세요.

5. code

c++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution {
public:
    int maximalSquare(vector<vector<char>>& matrix) {
        int DP[301][301]={0,};
        int h = matrix.size();
        int w = matrix[0].size();
        int result= 0;
        for(int i =0;i<h;++i){
            for(int j =0;j<w;++j){
                if(i==0 || j==0 || matrix[i][j]=='0')
                    DP[i][j] = matrix[i][j]-48;
                else
                {
                    DP[i][j] = min(DP[i-1][j-1],min(DP[i-1][j],DP[i][j-1])) +1;
                }
                result= max(result,DP[i][j]);
            }
        }
        return result*result;
        
    }
};

6. 결과 및 후기, 개선점

코드에 대한 설명이 필요하신 분은 댓글을 달아주세요.!!

c++ 60% python ??%

This post is licensed under CC BY 4.0 by the author.