File tree 2 files changed +24
-0
lines changed
solution/1500-1599/1572.Matrix Diagonal Sum
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,18 @@ func diagonalSum(mat [][]int) (ans int) {
133
133
134
134
### ** TypeScript**
135
135
136
+ ``` ts
137
+ function diagonalSum(mat : number [][]): number {
138
+ let ans = 0 ;
139
+ const n = mat .length ;
140
+ for (let i = 0 ; i < n ; ++ i ) {
141
+ const j = n - i - 1 ;
142
+ ans += mat [i ][i ] + (i === j ? 0 : mat [i ][j ]);
143
+ }
144
+ return ans ;
145
+ }
146
+ ```
147
+
136
148
``` ts
137
149
function diagonalSum(mat : number [][]): number {
138
150
const n = mat .length ;
Original file line number Diff line number Diff line change @@ -113,6 +113,18 @@ func diagonalSum(mat [][]int) (ans int) {
113
113
114
114
### ** TypeScript**
115
115
116
+ ``` ts
117
+ function diagonalSum(mat : number [][]): number {
118
+ let ans = 0 ;
119
+ const n = mat .length ;
120
+ for (let i = 0 ; i < n ; ++ i ) {
121
+ const j = n - i - 1 ;
122
+ ans += mat [i ][i ] + (i === j ? 0 : mat [i ][j ]);
123
+ }
124
+ return ans ;
125
+ }
126
+ ```
127
+
116
128
``` ts
117
129
function diagonalSum(mat : number [][]): number {
118
130
const n = mat .length ;
You can’t perform that action at this time.
0 commit comments