// Source : https://oj.leetcode.com/problems/set-matrix-zeroes/ // Author : Hao Chen // Date : 2014-06-23 /********************************************************************************** * * Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. * * click to show follow up. * * 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? * * **********************************************************************************/ class Solution { public: Solution(){ srand(time(NULL)); } void setZeroes(vector > &matrix) { if(random()%2){ setZeroes1(matrix); } setZeroes2(matrix); } void setZeroes1(vector > &matrix) { int bRow = false, bCol=false; for (int r=0; r > &matrix) { bool *row = new bool[matrix.size()](); bool *col = new bool[matrix[0].size()](); for (int r=0; r