leetcode

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

commit f3d6d1c6a9fd52d28c12847703641ae18970d711
parent bd34a359e0c93902880af95ca88559207f346127
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Wed, 15 Mar 2023 19:42:48 +0100

Daily Problem

Diffstat:
AProblems/0958.cpp | 20++++++++++++++++++++
MREADME.md | 1+
2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/Problems/0958.cpp b/Problems/0958.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + bool isCompleteTree(TreeNode *root) { + queue<TreeNode *> q; + int had_empty = 0; + q.push(root); + while (!q.empty()) { + TreeNode *root = q.front(); + q.pop(); + if (!root) { + had_empty = 1; + continue; + } + if (had_empty) return false; + q.push(root->left); + q.push(root->right); + } + return true; + } +}; diff --git a/README.md b/README.md @@ -349,6 +349,7 @@ for solving problems. | 0947 | Medium | [Most Stones Removed with Same Row or Column](Problems/0947.cpp) | | 0950 | Medium | [Reveal Cards In Increasing Order](Problems/0950.cpp) | | 0953 | Easy | [Verifying an Alien Dictionary](Problems/0953.cpp) | +| 0958 | Medium | [Check Completeness of a Binary Tree](Problems/0958.cpp) | | 0959 | Medium | [Regions Cut By Slashes](Problems/0959.cpp) | | 0965 | Easy | [Univalued Binary Tree](Problems/0965.cpp) | | 0973 | Medium | [K Closest Points to Origin](Problems/0973.cpp) |