bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 240. Search a 2D Matrix II

240. Search a 2D Matrix II

Leetcode Solutions

Search Space Reduction

  1. Start with a pointer at the bottom-left corner of the matrix.
  2. While the pointer is within the bounds of the matrix: a. If the current value is equal to the target, return true. b. If the current value is less than the target, move right (increment the column index). c. If the current value is greater than the target, move up (decrement the row index).
  3. If the target is not found and the pointer goes out of bounds, return false.
UML Thumbnail

Brute Force Search

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...