240 Search in a 2D matrix II
Write an efficient algorithm that searches for a value in an mxn matrix. This matrix has the following properties:
Integers in each row are sorted in ascending from left to right.
Integers in each column are sorted in ascending from top to bottom.
For example,
Consider the following matrix:
Given target=5
, returntrue
.
Given target=20
, returnfalse
.
L38 Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix, return the occurrence of it.
This matrix has the following properties:
Integers in each row are sorted from left to right.
Integers in each column are sorted from up to bottom.
No duplicate integers in each row or column.
Example
Consider the following matrix:
Given target =3
, return2
.
O(m+n) time and O(1) extra space
Last updated