#74

Search a 2D Matrix

specialist · 810 · lc medium +31 · verified · 53.6% accepted · 17,796 likes · top 45%

play →

Description

An m x n integer matrix has two properties: each row is non-decreasingly sorted, and the first element of each row is greater than the last element of the row above. Return true if target is in the matrix. The solution must run in O(log(m * n)) time.

Example 1:

Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
Output: true

Example 2:

Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
Output: false

Code

1
2
3