MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / searchMatrix

Method searchMatrix

Java/Search-a-2d-matrix.java:2–28  ·  view source on GitHub ↗
(int[][] matrix, int target)

Source from the content-addressed store, hash-verified

1class Solution {
2 public boolean searchMatrix(int[][] matrix, int target) {
3
4 if(matrix.length == 0 || matrix[0].length == 0){
5 return false;
6 }
7
8 if(matrix[matrix.length-1][matrix[0].length-1] < target){
9 return false;
10 }
11
12 for(int i=0; i<matrix.length; i++){
13 for(int j=0; j<matrix[i].length; j++){
14
15 if(matrix[i][j] > target){
16 return false;
17 }
18 else if(matrix[i][j] == target){
19 return true;
20 }
21 else{
22 continue;
23 }
24 }
25 }
26
27 return false;
28 }
29}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected