[LeetCode]Set Matrix Zeroes
发布日期:2021-11-22 02:48:57 浏览次数:2 分类:技术文章

本文共 562 字,大约阅读时间需要 1 分钟。

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.

Follow up:

Did you use extra space?
A straight forward solution using O(mn) space is probably a bad idea.
A simple improvement uses O(m + n) space, but still not the best solution.

Could you devise a constant space solution?

题解:使用两个boolean数组保存为0的位置。

public class Solution73 {	 public void setZeroes(int[][] matrix) {	 		 boolean rows[] = new boolean[matrix.length];		 boolean cols[] = new boolean[matrix[0].length];		 		 for(int i=0; i
这不是最好的空间复杂度O(n*m),不知道怎么用O(1)的解法。

转载地址:https://blog.csdn.net/zxdfc/article/details/48731845 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:[LeetCode]H-Index
下一篇:[LeetCode]Search a 2D Matrix

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月24日 03时06分37秒