Search a 2D Matrix
Return whether target occurs in a rectangular matrix whose rows increase and whose next row begins after the previous row ends. Use logarithmic time in the number of cells.
Example 1
matrix = [[1,4,8],[10,13,20]]
target = 13trueExplanation
13 occurs at row 1, column 1.
Example 2
matrix = [[1,4,8],[10,13,20]]
target = 9falseExplanation
9 lies between the two rows' ranges but is absent.
Example 3
matrix = [[7]]
target = 7trueExplanation
The only cell equals the target.
Constraints
- 1 <= rows, columns <= 100
- All cells are integers in strictly increasing flattened order
Function contract
searchMatrixArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[[1,4,8],[10,13,20]]13