We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在 N * N 的网格上,我们放置一些 1 * 1 * 1 的立方体。
N * N
1 * 1 * 1
每个值 v = grid[i][j] 表示 v 个正方体叠放在对应单元格 (i, j) 上。
v = grid[i][j]
v
(i, j)
请你返回最终形体的表面积。
Input: [[2]] Output: 10
Input: [[1,2],[3,4]] Output: 34
Input: [[1,0],[0,2]] Output: 16
Input: [[1,1,1],[1,0,1],[1,1,1]] Output: 32
Input: [[2,2,2],[2,1,2],[2,2,2]] Output: 46
1 <= N <= 50
0 <= grid[i][j] <= 50
The text was updated successfully, but these errors were encountered:
/** * @param {number[][]} grid * @return {number} */ var surfaceArea = function(grid) { let result = 0; let direction = [-1, 0, 1, 0, -1]; for (let i = 0 ; i < grid.length; i++) { for (let j = 0; j < grid[0].length; j++) { if (grid[i][j] !== 0) { result += grid[i][j] * 1 * 4 + 1 * 1 * 2; for (let d = 0; d < 4; d++) { let directionX = i + direction[d]; let directionY = j + direction[d + 1]; if (directionX >= 0 && directionX < grid.length && directionY >= 0 && directionY < grid.length ) { result -= Math.min(grid[i][j], grid[directionX][directionY]); } } } } } return result; };
Sorry, something went wrong.
No branches or pull requests
892. Surface Area of 3D Shapes
在
N * N
的网格上,我们放置一些1 * 1 * 1
的立方体。每个值
v = grid[i][j]
表示v
个正方体叠放在对应单元格(i, j)
上。请你返回最终形体的表面积。
Example 1
Example 2
Example 3
Example 4
Example 5
Note
1 <= N <= 50
0 <= grid[i][j] <= 50
The text was updated successfully, but these errors were encountered: