-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
1198.java
24 lines (22 loc) · 811 Bytes
/
1198.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
__________________________________________________________________________________________________
class Solution {
public int smallestCommonElement(int[][] mat) {
int n = mat.length;
int[] ps = new int[n];
int m = mat[0].length;
outer:
for(int i = 0;i < m;i++){
for(int j = 1;j < n;j++){
while(ps[j] < m && mat[j][ps[j]] < mat[0][i])ps[j]++;
if(ps[j] < m && mat[j][ps[j]] == mat[0][i]){
}else{
continue outer;
}
}
return mat[0][i];
}
return -1;
}
}
__________________________________________________________________________________________________
__________________________________________________________________________________________________