C++ 4 METHODS FAST EASY BEATS 100%
If I\'ve helped you with my codes below, Please UPVOTE (^~^)\n\nMETHOD 1: BRUTE FORCE :\n\nclass Solution {\npublic:\n    int diagonalSum(vector<vector<int>>& m
***If I\'ve helped you with my codes below, Please UPVOTE (^~^)***\n\n**METHOD 1: BRUTE FORCE :**\n```\nclass Solution {\npublic:\n    int diagonalSum(vector<vector<int>>& mat) {\n        \n        int m = mat.size() ;   // row\n        int n = mat[0].size() ;// column\n        \n        int sum = 0 ;\n        for ( int i = 0 ; i < m ; i++ ) {\n            for  ( int j = 0 ; j < n ; j++ ) {\n                \n                if( i==j ) sum += mat[i][j] ;      // primary diagonal\n                if( i+j == n-1 ) sum += mat[i][j] ;// secondary diagonal\n                \n            }\n        }\n        \n        if( m%2 == 0 ) return sum ;\n        else return sum - mat[m/2][n/2] ; // if odd size - then diagonal overlaps\n        \n    }\n};\n```\n\n\n**METHOD 2: O(n) T.C. Approach :**\n\n```\nclass Solution {\npublic:\n    int diagonalSum(vector<vector<int>>& mat) {\n        int i=0,j=0,sum=0;\n        int k=0,l=mat.size()-1;\n        while(i<mat.size()){\n            sum += mat[i++][j++];\n            if(k!=l)\n                sum += mat[k][l];\n            k++;\n            l--;\n        }\n        return sum;\n    }\n};\n```\n\n**METHOD 3: O(n) T.C. Approach :**\n```\nclass Solution {\npublic:\n    int diagonalSum(vector<vector<int>>& mat) {\n        int n = mat.size() ;\n\t\tint sum = 0;\n        for(int i = 0; i < n ; i++ ) {\n            if( i != n-i-1 ) sum += mat[i][i] + mat[i][n-i-1] ;\n            else sum += mat[i][i] ;   \n        }\n        return sum :\n    }\n};\n```\n\n\n\n**METHOD 4: 1 LINER FANS XD**\n\n```\nint diagonalSum(vector<vector<int>>& m, int i = -1) {\n    return accumulate(begin(m), end(m), 0, [&](int s, vector<int> &v){\n       return s + v[++i] + (i == v.size() - i - 1 ? 0 : v[v.size() - i - 1]);\n    });\n}\n```\n***If you like my solution Please UPVOTE (^~^)***
['C']