You are viewing a single comment's thread. Return to all comments →
My c# code.
public static int hourglassSum(List<List<int>> arr) { int sum =arr[0][0] + arr[0][1]+arr[0][2]+arr[1][1]+arr[2][0]+arr[2][1]+arr[2][2]; for(int i=0;i<4;i++) { int newSum =0; for(int j=0;j<4 ;j++) { newSum = arr[i][j]+arr[i][j+1]+arr[i][j+2] +arr[i+1][j+1] +arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2]; if(sum < newSum) { sum = newSum; } } } return sum; }
Seems like cookies are disabled on this browser, please enable them to open this website
2D Array - DS
You are viewing a single comment's thread. Return to all comments →
My c# code.