Microsoft Interview: transforming a matrix

后端 未结 5 2101
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 11:37

Given a matrix of size n x m filled with 0\'s and 1\'s

e.g.:

1 1 0 1 0

0 0 0 0 0

0 1 0 0 0

1 0 1 1 0

if the matrix has 1 a

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-30 12:21

    Another solution would be to scan the matrix as usual, and at the first 1 you split the matrix in 4 quadrants. You then set the line and the column to 1's, and recursively process each quadrant. Just make sure to set the whole columns and rows, even though you are scanning only a quadrant.

提交回复
热议问题