File tree Expand file tree Collapse file tree 1 file changed +3
-24
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +3
-24
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
- /**
4
- * 74. Search a 2D Matrix
5
- *
6
- * Write an efficient algorithm that searches for a value in an m x n matrix.
7
- * This matrix has the following properties:
8
-
9
- Integers in each row are sorted from left to right.
10
- The first integer of each row is greater than the last integer of the previous row.
11
- For example,
12
-
13
- Consider the following matrix:
14
-
15
- [
16
- [1, 3, 5, 7],
17
- [10, 11, 16, 20],
18
- [23, 30, 34, 50]
19
- ]
20
-
21
- Given target = 3, return true.
22
-
23
- */
24
3
public class _74 {
25
4
26
5
public static class Solution1 {
27
6
public boolean searchMatrix (int [][] matrix , int target ) {
28
7
if (matrix == null || matrix .length == 0
29
- || matrix [0 ].length == 0
30
- || matrix [0 ][0 ] > target
31
- || matrix [matrix .length - 1 ][matrix [0 ].length - 1 ] < target ) {
8
+ || matrix [0 ].length == 0
9
+ || matrix [0 ][0 ] > target
10
+ || matrix [matrix .length - 1 ][matrix [0 ].length - 1 ] < target ) {
32
11
return false ;
33
12
}
34
13
int m = matrix .length ;
You can’t perform that action at this time.
0 commit comments