Practice Search a 2D Matrix II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Return whether target occurs in the given m by n matrix. Values are nondecreasing from left to right within each row and from top to bottom within each column. No additional ordering between the end of one row and the start of the next is guaranteed.
Source: Search a 2D Matrix II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5
Output
true
# Example 2
Input
matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20
Output
false
Constraints
m == matrix.length
n == matrix[i].length
1 <= n, m <= 300
-10^9 <= matrix[i][j] <= 10^9
All the integers in each row are sorted in ascending order.
All the integers in each column are sorted in ascending order.
-10^9 <= target <= 10^9
Related LeetCode Problems
Practice more problems similar to Search a 2D Matrix II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.