Simple O(n) Solution C++ | Time Complexity O(1)
The approach is rather simple. All you need to do is traverse row wise. The left diagonal will have i==j values. The right diagonal on the other hand will have 
The approach is rather simple. All you need to do is traverse row wise. The left diagonal will have i==j values. The right diagonal on the other hand will have values where i==size-1-j. Keep the sum in two different variable as leftSum and RightSum. In the end, if your matrix has odd number of rows, this means that there is one common element in diagonal which would be middle element. Subtract it and you will get the sum.\n```\nclass Solution {\npublic:\n    int diagonalSum(vector<vector<int>>& mat) {\n        //Variables to Store diagonal Sum\n\t\tint diag1=0,diag2=0;\n        for(int i=0;i<mat.size();i++){\n\t\t\t//Left diagonal where  i==j (here, I have kept i=j)\n            diag1+=mat[i][i];\n\t\t\t//Right Diagonal where i==mat.size()-i-1\n            diag2+=mat[i][mat[0].size()-1-i];\n        }\n\t\t//Check if the we have a common diagonal. If yes, then remove it.\n        if(mat.size()%2!=0){\n            diag1-=mat[mat.size()/2][mat.size()/2];\n        }\n\t\t//Return the Sum\n        return diag1+diag2;\n    }\n};\n```\n\n**Share and Upvote if you like the Solution.**
['C', 'Matrix', 'C++']