File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -381,6 +381,7 @@ mod q797;
381381mod q803;
382382mod q804;
383383mod q806;
384+ mod q807;
384385mod q810;
385386mod q811;
386387mod q819;
Original file line number Diff line number Diff line change 1+ use crate :: q:: Solution ;
2+
3+ #[ allow( unused) ]
4+ impl Solution {
5+ pub fn max_increase_keeping_skyline ( grid : Vec < Vec < i32 > > ) -> i32 {
6+ // 方法1
7+ // 求出行和列的最大值,然后迭代每个单元,取当前单元行列最大值的最小值
8+ // AC 0ms 2.3mb 133/133
9+ let mut n = grid. len ( ) ;
10+ let mut m = grid[ 0 ] . len ( ) ;
11+ let mut row_max = vec ! [ 0 ; n] ;
12+ let mut col_max = vec ! [ 0 ; m] ;
13+ for row in 0 ..n {
14+ row_max[ row] = * grid[ row] . iter ( ) . max ( ) . unwrap ( ) ;
15+ }
16+ for col in 0 ..m {
17+ let mut max = 0 ;
18+ for row in 0 ..n {
19+ max = max. max ( grid[ row] [ col] ) ;
20+ }
21+ col_max[ col] = max;
22+ }
23+ let mut ans = 0 ;
24+ for row in 0 ..n {
25+ for col in 0 ..m {
26+ ans += row_max[ row] . min ( col_max[ col] ) - grid[ row] [ col] ;
27+ }
28+ }
29+ ans
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments