Skip to content

Commit 58858b6

Browse files
committed
Added README.md file for Matrix Diagonal Sum
1 parent be33784 commit 58858b6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

1677-matrix-diagonal-sum/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<h2><a href="https://leetcode.com/problems/matrix-diagonal-sum">Matrix Diagonal Sum</a></h2> <img src='https://img.shields.io/badge/Difficulty-Easy-brightgreen' alt='Difficulty: Easy' /><hr><p>Given a&nbsp;square&nbsp;matrix&nbsp;<code>mat</code>, return the sum of the matrix diagonals.</p>
2+
3+
<p>Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
<img alt="" src="https://assets.leetcode.com/uploads/2020/08/14/sample_1911.png" style="width: 336px; height: 174px;" />
8+
<pre>
9+
<strong>Input:</strong> mat = [[<strong>1</strong>,2,<strong>3</strong>],
10+
&nbsp; [4,<strong>5</strong>,6],
11+
&nbsp; [<strong>7</strong>,8,<strong>9</strong>]]
12+
<strong>Output:</strong> 25
13+
<strong>Explanation: </strong>Diagonals sum: 1 + 5 + 9 + 3 + 7 = 25
14+
Notice that element mat[1][1] = 5 is counted only once.
15+
</pre>
16+
17+
<p><strong class="example">Example 2:</strong></p>
18+
19+
<pre>
20+
<strong>Input:</strong> mat = [[<strong>1</strong>,1,1,<strong>1</strong>],
21+
&nbsp; [1,<strong>1</strong>,<strong>1</strong>,1],
22+
&nbsp; [1,<strong>1</strong>,<strong>1</strong>,1],
23+
&nbsp; [<strong>1</strong>,1,1,<strong>1</strong>]]
24+
<strong>Output:</strong> 8
25+
</pre>
26+
27+
<p><strong class="example">Example 3:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> mat = [[<strong>5</strong>]]
31+
<strong>Output:</strong> 5
32+
</pre>
33+
34+
<p>&nbsp;</p>
35+
<p><strong>Constraints:</strong></p>
36+
37+
<ul>
38+
<li><code>n == mat.length == mat[i].length</code></li>
39+
<li><code>1 &lt;= n &lt;= 100</code></li>
40+
<li><code>1 &lt;= mat[i][j] &lt;= 100</code></li>
41+
</ul>

0 commit comments

Comments
 (0)