leetcode -- Set Matrix Zeroes -- 很有意思的题目,多看

https://leetcode.com/problems/set-matrix-zeroes/

思路1 O(m*n) space

忽略

思路2 O(m +n) space

http://www.cnblogs.com/zuoyuan/p/3769698.html
扫一遍记录每行每列是否有0,
然后再扫一遍set zeros

思路3 O(1) space 最优

利用matrix的第一行 和第一列来作为思路2中的辅助向量。不过要首先check一下,第一行或者第一列是否本身就有0,有的话,就先记录下来,等到把其余行列的set zeroes做完,再处理第一行或者第一列是否也要set zeroes.
http://blog.csdn.net/kenden23/article/details/17420747

http://www.lifeincode.net/programming/leetcode-set-matrix-zeroes-java/

你可能感兴趣的:(LeetCode)