Search a 2D Matrix (first time)

after:

对比我前后的两种做法,其实做法类似,但是将end的值设置为length而非length -1,可以减少许多不必要的判断。

我们也可以将整个matrix做一个整体的binary search, 在此情况下,start = 0;end = m * n

A binary search across the entire array becomes more difficult if the matrix is sparse. In those cases it's better to find the row (binary search) first, then the column (also binary search). The time complexity is the same when the matrix is square and dense, but it also works when the matrix has different length rows.

results matching ""

    No results matching ""