Algorithm: how to find a column in matrix filled with all 1, time complexity O(n)?

前端 未结 5 799
野的像风
野的像风 2020-12-11 05:40

I have a matrix which looks like this:

| 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 | 0 |
| 1 | 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 | 0 |
| 0 | 0 | 0 | 1 | 1 |
<         


        
5条回答
  •  粉色の甜心
    2020-12-11 06:00

    What is the input for the matrix?

    If you get a number for each column, i.e. in your example (in decimal) 14, 8, 4, 31, 1, you could just create a number a with n binary digits set to 1 (in this case 31). If this number is equal to one of the column numbers, one of the columns is all 1s.

提交回复
热议问题