[Leetcode][240. Search a 2D Matrix II] 5 Approaches: BF, Binary Search(Row), Binary Search(Diagonal, Row, Col), Binary Search(Global), 2D Coord Axis
By Long Luo
This article is the solution 5 Approaches: BF, Binary Search(Row), Binary Search(Diagonal, Row, Col), Binary Search(Global), 2D Coord Axis of Problem 240. Search a 2D Matrix II.
The similar question and solution is 74. Search a 2D Matrix.
Here shows 5 Approaches to slove this problem: Brute Force, Binary Search(Row), Binary Search(Diagonal, Row, Col), Binary Search(Global), 2D Coord Axis.
Brute Force
1 | public static boolean searchMatrix_bf(int[][] matrix, int target) { |
Analysis
- Time Complexity: .
- Space Complexity: .
Binary Search(Row)
1 | public boolean searchMatrix_bs_row(int[][] matrix, int target) { |
Analysis
- Time Complexity: .
- Space Complexity: .
Binary Search(Diagonal, Row, Col)
1 | public static boolean searchMatrix_bs_3d(int[][] matrix, int target) { |
Analysis
- Time Complexity: .
- Space Complexity: .
Binary Search(Global)
1 | public static boolean searchMatrix_bs(int[][] matrix, int target) { |
Analysis
- Time Complexity: .
- Space Complexity: .
2D Coord Axis
1 | public static boolean searchMatrix_coord_left(int[][] matrix, int target) { |
Analysis
- Time Complexity: .
- Space Complexity: .
All suggestions are welcome.
If you have any query or suggestion please comment below.
Please upvote👍 if you like💗 it. Thank you:-)
Explore More Leetcode Solutions. 😉😃💗