Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6c280e4

Browse files
author
guangsheng.li01
committed
Solved 0883
1 parent 1c14b21 commit 6c280e4

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod a0617_merge_two_binary_trees;
2727
mod a0643_maximum_average_subarray_i;
2828
mod a0646_maximum_length_of_pair_chain;
2929
mod a0867_transpose_matrix;
30+
mod a0883_projection_area_of_3d_shapes;
3031
mod a0929_unique_email_addresses;
3132
mod a0931_minimum_falling_path_sum;
3233
mod a0937_reorder_data_in_log_files;

0 commit comments

Comments
 (0)