-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path699.txt
More file actions
30 lines (24 loc) · 774 Bytes
/
Copy path699.txt
File metadata and controls
30 lines (24 loc) · 774 Bytes
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
class Solution {
public List<Integer> fallingSquares(int[][] A) {
long max=0;
List<Integer>res=new ArrayList<>();
List<long[]>list=new ArrayList<>();
list.add(new long[]{0,Integer.MAX_VALUE,0});
//can not sort
for(int i=0;i<A.length;i++){
int pair[]=A[i];
long len=pair[1];
long l=pair[0],r=l+len-1;
long m=0;
for(long pos[]:list){
if(pos[1]<l)continue;
if(pos[0]>r)continue;
m=Math.max(m,pos[2]+len);
}
list.add(new long[]{l,r,m});
max=Math.max(max,m);
res.add((int)(max));
}
return res;
}
}