10 Different Methods😎 | C++ | 👩‍💻✔
2 Simple Methods: ( Lol, 2 hi hai )\n\n1. Add all the diagonal elements from top to bottom, then from bottom to top, if n is odd then subtract middle element of
2 Simple Methods: ( Lol, 2 hi hai )\n\n1. Add all the diagonal elements from top to bottom, then from bottom to top, if n is odd then subtract middle element of matrix otherwise return as it is.\n\n2. Simultaenously add from both start and end in a row, for ```Primary Diagonal``` when row = i and col = i(mat[ i ][ i ]), for ```Secondary Diagonal``` when row = i and col = n-i-1 (mat[ i ][ n-i-1 ])\n\n```NOTE: Yaha tak aaye ho to ek vote mai kya bigad jayega\uD83D\uDE01```\n\n# Code\nMethod 1:\n```\nclass Solution {\npublic:\n    int diagonalSum(vector<vector<int>>& mat) {\n        int n=mat.size();\n        int sum=0;\n        int i=0,j=0;\n        while(i<n){\n            sum += mat[i++][j++];\n        }\n\n        i=n-1,j=0;\n\n        while(i>=0){\n            sum += mat[i--][j++];\n        }\n\n        if(n%2 != 0){\n            return sum - mat[n/2][n/2];\n        }\n        return sum;\n    }\n};\n```\nMethod 2:\n```\nclass Solution {\npublic:\n    int diagonalSum(vector<vector<int>>& mat) {\n        int n=mat.size();\n        int sum=0;\n        int i=0;\n        while(i<n){\n            sum += mat[i][i];\n            if(n-i-1 != i) sum += mat[i][n-i-1];\n            i++;\n        }\n        return sum;\n    }\n};\n```\n\n![please upvote.png](https://assets.leetcode.com/users/images/b11b3285-d374-4a6d-9c78-df4bae196c8d_1683525562.6482232.png)\n
['C++']