Set Matrix Zeroes

Given an `m x n` matrix, if an element is 0, set its entire row and column to 0. Do it in-place with constant extra space (by using first row/column as markers).

Input Format

2D list of ints.

Output Format

Modified matrix in-place.

Constraints

  • m,n ≤ 200.

Examples

Example 1:

Input:

matrix = [[1,1,1],[1,0,1],[1,1,1]]

Output:

[[1,0,1],[0,0,0],[1,0,1]]

Explanation:

The zero at (1,1) causes its row and column to become all 0s.

Loading...
Set Matrix Zeroes - Matrix DSA Problem