Goland DP solution


  • 0
    R
    func maximalSquare(a [][]byte) int {
        if len(a) == 0 { return 0 }
        m := len(a)
        n := len(a[0])
        result:=0;
        b:= make([][]int, m + 1)
        for k, _ := range b {
            b[k] = make([]int, n + 1)
            for j,_ := range b[k] {
                b[k][j] = 0
            }
        }
    
        for i := 1; i <= m; i++ {
            for j := 1; j <= n; j++ {
                if(a[i-1][j-1] == '1') {
                    b[i][j] = min(min(b[i][j-1], b[i-1][j-1]), b[i-1][j]) + 1;
                    result = max(b[i][j], result);
                }
            }
        }
        return result*result;
    }
    
    func min(a int, b int) int {
        if a > b {
            return b
        } else {
            return a
        }
    }
    
    func max(a int , b int) int {
        if a < b {
            return b
        } else {
            return a
        }
    }
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.