본문 바로가기

알고리즘 문제

Programmers Level 4 가장 큰 정사각형 찾기 ★

def findLargestSquare(board):

    col = len(board[0])

    row = len(board)

    mx=0

    dp=[[0]*col for i in range(row)]

    for i in range(1,row):

        for j in range(1,col):

            if board[i][j] == 'O':

                dp[i][j] = min(dp[i-1][j-1],dp[i-1][j],dp[i][j-1])+1

                if mx < dp[i][j]: mx=dp[i][j]

    return mx**2

testBoard = [['X','O','O','O','X'],['X','O','O','O','O'],['X','X','O','O','O'],['X','X','O','O','O'],['X','X','X','X','X']]

print(findLargestSquare(testBoard))