Diagonal Difference

  • + 0 comments

    My solution in C++

    int diagonalDifference(vector<vector<int>> arr) {
    int left_result = 0;
    int right_result = 0;
    int diagonalDiff = 0; 
    for (int i = 0; i < arr.size(); i++){
         
      left_result += arr[i][i];
      right_result += arr[i][arr.size()-i-1];
    }
    
    diagonalDiff = left_result - right_result;
    return abs(diagonalDiff);
    }