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.
funcsurfaceArea(A:[[Int]])->Int{// Write your code hereletH:Int=A.count-1letW:Int=A.first!.count-1vartotalSurface:Int=0forindex1in0...W{varlastNumberLeft=0varlastNumberRight=0forindex2in0...H{// calculate left facing cubeifA[index2][index1]>lastNumberLeft{totalSurface+=A[index2][index1]-lastNumberLeft}lastNumberLeft=A[index2][index1]// calculate right facing cubeifA[H-index2][W-index1]>lastNumberRight{totalSurface+=A[H-index2][W-index1]-lastNumberRight}lastNumberRight=A[H-index2][W-index1]}}forindex1in0...H{varlastNumberFront=0varlastNumberBack=0forindex2in0...W{// calculate front facing cubeifA[index1][index2]>lastNumberFront{totalSurface+=A[index1][index2]-lastNumberFront}lastNumberFront=A[index1][index2]// calculate back facing cubeifA[H-index1][W-index2]>lastNumberBack{totalSurface+=A[H-index1][W-index2]-lastNumberBack}lastNumberBack=A[H-index1][W-index2]}}return((H+1)*(W+1))*2+totalSurface}
Cookie support is required to access HackerRank
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 →
Swift: