/**
* @author WanZi
* @create 2022-10-13 18:17
*/
public class Main03 {
public int Trap (ArrayList<Integer> height) {
// write code here
int res = 0;
for(int i=0;i<height.size();i++){
if(i == 0 || i == height.size() - 1){
continue;
}
int l = height.get(i);
int r = height.get(i);
for(int rr = i+1;rr<height.size();rr++){
if(height.get(rr)>r){
r = height.get(rr);
}
}
for(int ll = i-1;ll>=0;ll--){
if(height.get(ll)>l){
l = height.get(ll);
}
}
int h = Math.min(l,r) - height.get(i);
if(h > 0){
res += h;
}
}
return res;
}
}
接雨水-入参为ArrayList<Integer>类型
最新推荐文章于 2024-11-05 11:47:58 发布