Zero Out Rows and Columns
For every cell equal to 0, set its entire row and column to 0. Return the resulting matrix.
Requirements
- The -space version uses the first row and column as markers.
Examples
EXAMPLE WALKTHROUGHcentre zero
A guided view of the published example, not a trace of your code.
INPUT
[[[1,1,1],[1,0,1],[1,1,1]]]TASKzero_out_rows_and_columns()
EXPECTED OUTPUT
[[1,0,1],[0,0,0],[1,0,1]]Start with the input values shown in this example.
Example 1 of 3
Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]
Output: [[1,0,1],[0,0,0],[1,0,1]]
Explanation: centre zero
Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
Explanation: two zeros
Input: matrix = [[5]]
Output: [[5]]
Explanation: no zeros
Hint 1
First record which rows and columns contain a zero, then rewrite.