File tree 3 files changed +58
-2
lines changed
3 files changed +58
-2
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[][] } mat
3
+ * @return {number }
4
+ */
5
+ var diagonalSum = function ( mat ) {
6
+ let sum = 0 , l = 0 , r = mat [ 0 ] . length - 1 ;
7
+
8
+ for ( let row = 0 ; row < mat . length ; row ++ ) {
9
+ // for (let c = 0; c < mat[r].length; c++) {
10
+ console . log ( `mat[row][l]:${ mat [ row ] [ l ] } , mat[row][r]:${ mat [ row ] [ r ] } ` )
11
+ if ( l === r ) { // intersect
12
+ sum += mat [ row ] [ l ] ;
13
+ } else {
14
+ sum += mat [ row ] [ l ] + mat [ row ] [ r ] ;
15
+ }
16
+
17
+ l ++ ;
18
+ r -- ;
19
+ // }
20
+ }
21
+
22
+ return sum ;
23
+ } ;
24
+
25
+ let x = null ;
26
+ x = diagonalSum ( [
27
+ [ 1 , 2 , 3 ] ,
28
+ [ 4 , 5 , 6 ] ,
29
+ [ 7 , 8 , 9 ]
30
+ ] )
31
+
32
+
33
+ console . log ( "Result" ) ;
34
+ console . log ( x ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[][] } mat
3
+ * @return {number }
4
+ */
5
+ var diagonalSum = function ( mat ) {
6
+ let sum = 0 , l = 0 , r = mat [ 0 ] . length - 1 ;
7
+
8
+ for ( let row = 0 ; row < mat . length ; row ++ ) {
9
+ if ( l === r ) {
10
+ sum += mat [ row ] [ l ] ;
11
+ } else {
12
+ sum += mat [ row ] [ l ] + mat [ row ] [ r ] ;
13
+ }
14
+
15
+ l ++ ;
16
+ r -- ;
17
+ }
18
+
19
+ return sum ;
20
+ } ;
21
+
Original file line number Diff line number Diff line change 74
74
- [ 1365. How Many Numbers Are Smaller Than the Current Number] ( ./1365/ )
75
75
- [ 1512. Number of Good Pairs] ( ./1512/ )
76
76
- [ 1569. Number of Ways to Reorder Array to Get Same BST] ( ./1569/ )
77
+ - [ 1572. Matrix Diagonal Sum] ( ./1572/ )
77
78
- [ 1672. Richest Customer Wealth] ( ./1672/ )
78
79
- [ 1791. Find Center of Star Graph] ( ./1791/ )
79
80
- [ 1909. Remove One Element to Make the Array Strictly Increasing] ( ./1909/ )
@@ -106,7 +107,7 @@ iex ./.../solution.ex
106
107
107
108
Batch create:
108
109
``` ssh
109
- chapter=997 && mkdir ./$chapter && touch ./$chapter/my_solution.ex && touch ./$chapter/solution.ex && alias x="iex ./$chapter/my_solution.ex"
110
+ chapter=1572 && mkdir ./$chapter && touch ./$chapter/my_solution.ex && touch ./$chapter/solution.ex && alias x="iex ./$chapter/my_solution.ex"
110
111
```
111
112
> then you can use ` x ` for quick debug.
112
113
@@ -128,7 +129,7 @@ Batch create:
128
129
NOTE: JS IS HERE
129
130
-->
130
131
``` ssh
131
- chapter=2448 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
132
+ chapter=1572 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
132
133
```
133
134
> then you can use ` x ` for quick debug.
134
135
You can’t perform that action at this time.
0 commit comments