We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defsurfaceArea(A):# Pad the grid width a layer of 0# for easier calculationa=[[0]*(len(A[0])+2)]forrowinA:a.append([0]+row+[0])a.append([0]*(len(A[0])+2))# Bottom and top areaans=len(A)*len(A[0])*2# Side area is just the sum of differences# between adjacent cells. Be careful not to# count a side twice.foriinrange(1,len(a)):forjinrange(1,len(a[i])):ans+=abs(a[i][j]-a[i-1][j])ans+=abs(a[i][j]-a[i][j-1])returnans
3D Surface Area
You are viewing a single comment's thread. Return to all comments →
Same idea in Python 3