Sorting a binary 2D matrix?

前端 未结 6 1341
伪装坚强ぢ
伪装坚强ぢ 2021-02-09 13:06

I\'m looking for some pointers here as I don\'t quite know where to start researching this one.

I have a 2D matrix with 0 or 1 in each cell, such as:

  1         


        
6条回答
  •  天命终不由人
    2021-02-09 13:34

    Treat rows as binary numbers, with the leftmost column as the most significant bit, and sort them in descending order, top to bottom

    Treat the columns as binary numbers with the bottommost row as the most significant bit and sort them in ascending order, left to right.

    Repeat until you reach a fixed point. Proof that the algorithm terminates left as an excercise for the reader.

提交回复
热议问题