You are viewing a single comment's thread. Return to all comments →
C++
int surfaceArea(vector<vector<int>> A) { int H = A.size(); int W = A[0].size(); int area = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (A[i][j] > 0) { area += 2; area += max(A[i][j] - (i > 0 ? A[i-1][j] : 0), 0); area += max(A[i][j] - (i < H-1 ? A[i+1][j] : 0), 0); area += max(A[i][j] - (j > 0 ? A[i][j-1] : 0), 0); area += max(A[i][j] - (j < W-1 ? A[i][j+1] : 0), 0); } } } return area; }
Seems like cookies are disabled on this browser, please enable them to open this website
3D Surface Area
You are viewing a single comment's thread. Return to all comments →
C++