P14270 [GeeksforGeeks] Coverage of all zeros in a binary matrix4024
普及-
题目描述

Given a binary matrix having n rows and m columns, your task is to find the sum of coverage of all zeros in the matrix where coverage for a particular 0 is defined as total number of ones around a zero in left, right, up and bottom directions.

Example 1:
Input: matrix = {{0, 1, 0},
{0, 1, 1}, {0, 0, 0}}
Output: 6
Example 2:
Input: matrix = {{0, 1}}
Output: 1

Your Task:
You don't need to read or print anyhting. Your task is to complete the function FindCoverage() which takes the matrix as input parameter and returns sum of coverage of all zeros in the matrix.

Expected Time Complexity: O(n * m)
Expected Space Complexity: O(1)

Constraints:
1 <= n, m <= 100

输入格式

见题面

输出格式

见题面

样例输入
matrix = {{0, 1, 0}, {0, 1, 1}, {0, 0, 0}}
样例输出
6