File tree 2 files changed +43
-0
lines changed
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * [0883] projection-area-of-3d-shapes
3
+ */
4
+
5
+ pub struct Solution { }
6
+
7
+ // solution impl starts here
8
+
9
+ use std:: cmp:: max;
10
+ impl Solution {
11
+ pub fn projection_area ( grid : Vec < Vec < i32 > > ) -> i32 {
12
+ let mut area = 0 ;
13
+ let ( mut max_row, mut max_col) ;
14
+ for i in 0 ..grid. len ( ) {
15
+ max_row = 0 ;
16
+ max_col = 0 ;
17
+ for j in 0 ..grid. len ( ) {
18
+ area += if grid[ i] [ j] > 0 { 1 } else { 0 } ;
19
+ max_row = max ( max_row, grid[ i] [ j] ) ;
20
+ max_col = max ( max_col, grid[ j] [ i] ) ;
21
+ }
22
+ area += max_row + max_col;
23
+ }
24
+ area
25
+ }
26
+ }
27
+
28
+ // solution impl ends here
29
+
30
+ // solution tests starts here
31
+
32
+ #[ cfg( test) ]
33
+ mod tests {
34
+ use super :: * ;
35
+
36
+ #[ test]
37
+ fn test_case0 ( ) {
38
+ assert_eq ! ( Solution :: projection_area( vec![ vec![ 2 ] ] ) , 5 ) ;
39
+ }
40
+ }
41
+
42
+ // solution tests ends here
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ mod a0617_merge_two_binary_trees;
27
27
mod a0643_maximum_average_subarray_i;
28
28
mod a0646_maximum_length_of_pair_chain;
29
29
mod a0867_transpose_matrix;
30
+ mod a0883_projection_area_of_3d_shapes;
30
31
mod a0929_unique_email_addresses;
31
32
mod a0931_minimum_falling_path_sum;
32
33
mod a0937_reorder_data_in_log_files;
You can’t perform that action at this time.
0 commit comments