You are viewing a single comment's thread. Return to all comments →
C++:
int GetLeftToRightDiagSum(vector<vector<int>>& arr) { int sum = 0; for(int i = 0; i < arr.size(); i++) { sum+= arr[i][i]; } return sum; } int GetRightToLeftDiagSum(vector<vector<int>>& arr) { int sum = 0; int int_arr_size = arr[0].size() - 1; for(int i = 0; i < arr.size(); i++) { sum+= arr[i][int_arr_size - i]; } return sum; } int diagonalDifference(vector<vector<int>> arr) { int a = GetLeftToRightDiagSum(arr); int b = GetRightToLeftDiagSum(arr); return (a > b) ? (a-b) : (b-a); }
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
C++: