|
| 1 | +<p>Given an <code>m x n</code> integer matrix <code>matrix</code>, if an element is <code>0</code>, set its entire row and column to <code>0</code>'s.</p> |
| 2 | + |
| 3 | +<p>You must do it <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in place</a>.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | +<img alt="" src="https://assets.leetcode.com/uploads/2020/08/17/mat1.jpg" style="width: 450px; height: 169px;" /> |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> matrix = [[1,1,1],[1,0,1],[1,1,1]] |
| 10 | +<strong>Output:</strong> [[1,0,1],[0,0,0],[1,0,1]] |
| 11 | +</pre> |
| 12 | + |
| 13 | +<p><strong class="example">Example 2:</strong></p> |
| 14 | +<img alt="" src="https://assets.leetcode.com/uploads/2020/08/17/mat2.jpg" style="width: 450px; height: 137px;" /> |
| 15 | +<pre> |
| 16 | +<strong>Input:</strong> matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]] |
| 17 | +<strong>Output:</strong> [[0,0,0,0],[0,4,5,0],[0,3,1,0]] |
| 18 | +</pre> |
| 19 | + |
| 20 | +<p> </p> |
| 21 | +<p><strong>Constraints:</strong></p> |
| 22 | + |
| 23 | +<ul> |
| 24 | + <li><code>m == matrix.length</code></li> |
| 25 | + <li><code>n == matrix[0].length</code></li> |
| 26 | + <li><code>1 <= m, n <= 200</code></li> |
| 27 | + <li><code>-2<sup>31</sup> <= matrix[i][j] <= 2<sup>31</sup> - 1</code></li> |
| 28 | +</ul> |
| 29 | + |
| 30 | +<p> </p> |
| 31 | +<p><strong>Follow up:</strong></p> |
| 32 | + |
| 33 | +<ul> |
| 34 | + <li>A straightforward solution using <code>O(mn)</code> space is probably a bad idea.</li> |
| 35 | + <li>A simple improvement uses <code>O(m + n)</code> space, but still not the best solution.</li> |
| 36 | + <li>Could you devise a constant space solution?</li> |
| 37 | +</ul> |
0 commit comments