240. Search a 2D Matrix II

the idea is to start from the right top corner (biggest in this row), so we can conclude:

current value == target, return true

current value > target, should do col--, or

should row++, find next row

time: O(m+n)

space: O(1)

Last updated

Was this helpful?