careercup / CtCI-6th-Edition

Cracking the Coding Interview 6th Ed. Solutions
11.33k stars 4.41k forks source link

Java/Ch 01. Arrays and Strings/Q1_08_Zero_Matrix/QuestionB.java #182

Closed GaiNingMorris closed 4 years ago

GaiNingMorris commented 4 years ago

What is the point to separate the first row and column with the rest ones ? why not just check at once:

for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { if (matrix[i][j] == 0) { matrix[i][0] = 0; matrix[0][j] = 0; } } }