-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindInArray.java
More file actions
49 lines (47 loc) · 1.21 KB
/
FindInArray.java
File metadata and controls
49 lines (47 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*public class Solution {
public boolean Find(int target, int [][] array) {
if(array==null||array.length==0||(array.length==1&&array[0].length==0))
return false ;
int row = array.length;
for(int i=0;i<row;i++)
{
int col= array[i].length;
if(target==array[i][col-1])
return true;
if(target<array[i][col-1])
{
for(int j=0;j<col;j++)
{
if(array[i][j]==target)
{
return true;
}
}
}
}
return false;
}
}
*/
public class Solution {
public boolean Find(int target, int [][] array)
{
int row = array.length-1;
int i = 0;
while(row>=0&&i<array[0].length)
{
if(target<array[row][i])
{
row--;
}
else if(target>array[row][i])
{
i++;
}
else{
return true;
}
}
return false;
}
}