Projection Area of 3D Shapes

给一个grids, 里面是3d的unit tube, 求三面投影.

这题读懂这个grids的设计即可. 还有个测试是value = 0…

class Solution {
    public int projectionArea(int[][] grid) {
        int n = grid.length;
        int m = grid[0].length;
        int xy = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++){
                if(grid[i][j] != 0)
                   xy++; 
            }
        }      
        int xz = 0; 
        for(int i = 0; i < n; i++) {
            int max = 0;
            for(int j = 0; j < m; j++){
                if(grid[i][j] != 0)
                    max = Math.max(max,grid[i][j]);
            }
            xz += max;
        }
        int zy = 0;
        for(int j = 0; j < m; j++) {
            int max = 0;
            for(int i = 0; i < n; i++){
                if(grid[i][j] != 0)
                    max = Math.max(max,grid[i][j]);
            }
            zy += max;
        }
        return xy + xz + zy;
    }
}