Set Matrix Zeroes

Medium

Topics
ArrayHash TableMatrix

Given an m x n matrix, if an element is 0 set its entire row and column to 0. LeetCode mutates in place; here return the modified matrix.

Example 1

Input:  grid = [[1,1,1],[1,0,1],[1,1,1]]
Output: [[1,0,1],[0,0,0],[1,0,1]]

Example 2

Input:  grid = [[0,1],[1,1]]
Output: [[0,0],[0,1]]

Constraints

  • 1 <= m, n <= 200
  • -2^31 <= matrix[i][j] <= 2^31 - 1
Run ⌘' · Submit ⌘⏎