Unofficial C Solution to Problem 1.7 in Cracking the Coding Interview (5th Edition)

23 Mar

In this question, we have to travel the matrix twice. In the first time, we need to record which rows and columns contain zero element. And in the second round, we will set these rows and columns entirely zero.

By the way, in this case, we could not set zero while in the first travel. If we did so, once meet with a zero element, we set its entire row and column to zero. It might change some of the remaining non-zero element to zero. Later, when we meet with these changed elements, we will set its entire row and column to zero, while we should not.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!