持续更新中。。。。。。。。。。。。。。
day 20230811
/*** 给你一个正方形矩阵 mat,请你返回矩阵对角线元素的和。* <p>* 请你返回在矩阵主对角线上的元素和副对角线上且不在主对角线上元素的和* <p>* 不包括 相交的元素只计算一次* <p>* 输入:mat = [[1,2,3],* [4,5,6],* [7,8,9]]* 输出:25* 解释:对角线的和为:1 + 5 + 9 + 3 + 7 = 25* 请注意,元素 mat[1][1] = 5 只会被计算一次。*/
public class num1572 {public int diagonalSum(int[][] mat) {int res = 0;if (mat.length == 0 || mat.length != mat[0].length) return 0;int rows = mat.length;for (int i = 0; i < rows; i++) {res += mat[i][i] + mat[i][rows - 1 - i];if (i == rows - 1 - i) {res -= mat[i][i];}}return res;}}