cjql / algorithm

https://cjql.github.io/algorithm/
1 stars 1 forks source link

LeetCode_Dynamic: https://leetcode.com/problems/count-square-submatrices-with-all-ones/submissions/ #4

Open cjql opened 4 years ago

cjql commented 4 years ago

C++

Java

Python

class Solution:
    def countSquares(self, matrix: List[List[int]]) -> int:
        for i in range(1,len(matrix)):
            for j in range(1,len(matrix[0])):
                matrix[i][j] *= min(matrix[i-1][j],matrix[i][j-1],matrix[i-1][j-1])+1
        return sum(map(sum,matrix))

C

C

JavaScript

Ruby

Swift

Go

Scala

Kotlin

Rust

PHP