leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 1943c2489fa9ed85dea5494cf6c517c47db5302c
parent e308ff16ba6fe3f558eef1c9312e54030afecf30
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Mon,  8 May 2023 13:09:58 +0200

Daily Problem

Diffstat:
AProblems/1572.cpp | 10++++++++++
MREADME.md | 1+
2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/Problems/1572.cpp b/Problems/1572.cpp @@ -0,0 +1,10 @@ +class Solution { +public: + int diagonalSum(vector<vector<int>> &mat) { + int n = mat.size(), sum = 0; + for (int i = 0; i < n; i++) sum += mat[i][i] + mat[i][n - i - 1]; + + if (n % 2) sum -= mat[n / 2][n / 2]; + return sum; + } +}; diff --git a/README.md b/README.md @@ -459,6 +459,7 @@ for solving problems. | 1544 | Easy | [Make The String Great](Problems/1544.cpp) | | 1557 | Medium | [Minimum Number of Vertices to Reach All Nodes](Problems/1557.cpp) | | 1567 | Medium | [Maximum Length of Subarray With Positive Product](Problems/1567.cpp) | +| 1572 | Easy | [Matrix Diagonal Sum](Problems/1572.cpp) | | 1579 | Hard | [Remove Max Number of Edges to Keep Graph Fully Traversable](Problems/1579.cpp) | | 1584 | Medium | [Min Cost to Connect All Points](Problems/1584.cpp) | | 1609 | Medium | [Even Odd Tree](Problems/1609.cpp) |