标签:find when ase time either hat bin first row
Given a matrix, like this
[[0, 0, 1, 1, 1]
[0, 1, 1, 1, 1]
[0, 0, 1, 1, 1]
[0, 0, 0, 0, 0]]
each cell is either 1 or 0
in each row, from left to right, when you first see a number 1 in the cell, then the rest cells in this row will all be 1
Question: please find the leftmost column that has number 1
解法1:
For each row, do binary search and find the left most column that has number 1.
Time complexity: O(m * lgn)
解法2:
Start from the top right element, if current value is 1, move left, otherwise, move down.
Time complexity: O(m + n)
find the leftmost column that has number 1
标签:find when ase time either hat bin first row
原文地址:https://www.cnblogs.com/beiyeqingteng/p/12272344.html