持續更新中。。。。。。。。。。。。。。
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;}}