892. Surface Area of 3D Shapes Easy

@problem@discussion
#Array#Math#Geometry#Matrix



1/**
2 * [892] Surface Area of 3D Shapes
3 *
4 * You are given an n x n grid where you have placed some 1 x 1 x 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of cell (i, j).
5 * After placing these cubes, you have decided to glue any directly adjacent cubes to each other, forming several irregular 3D shapes.
6 * Return the total surface area of the resulting shapes.
7 * Note: The bottom face of each shape counts toward its surface area.
8 *  
9 * Example 1:
10 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/08/tmp-grid2.jpg" style="width: 162px; height: 162px;" />
11 * Input: grid = [[1,2],[3,4]]
12 * Output: 34
13 * 
14 * Example 2:
15 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/08/tmp-grid4.jpg" style="width: 242px; height: 242px;" />
16 * Input: grid = [[1,1,1],[1,0,1],[1,1,1]]
17 * Output: 32
18 * 
19 * Example 3:
20 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/08/tmp-grid5.jpg" style="width: 242px; height: 242px;" />
21 * Input: grid = [[2,2,2],[2,1,2],[2,2,2]]
22 * Output: 46
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	n == grid.length == grid[i].length
28 * 	1 <= n <= 50
29 * 	0 <= grid[i][j] <= 50
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/surface-area-of-3d-shapes/
35// discuss: https://leetcode.com/problems/surface-area-of-3d-shapes/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn surface_area(grid: Vec<Vec<i32>>) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_892() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.