EASIEST 2 LINES JAVA SOLUTION BEATING 100% in 0ms
Complexity
Time complexity: O(n)

Space complexity: O(1)
Code
![image.png](https://assets.leetcode.com/users/images/f86004c5-ef25-4e45-83aa-69fa3b8eef65_1737874840.141648.png)

# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int diagonalSum(int[][] mat) {
        int n=mat.length,m=mat[0].length;
        int sum=0;
        for(int i=0;i<n;i++){
            sum += mat[i][i];
            if (i != n - i - 1) {
                sum += mat[i][n - i - 1];
            }
        }
        return sum;
    }
}
```
![Upvote.PNG](https://assets.leetcode.com/users/images/c66cdb9f-336a-412b-8297-916afb5609e1_1737874860.743667.png)

['Array', 'Matrix', 'Java']