leetcode

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

0958.cpp (479B)


      1 class Solution {
      2   public:
      3     bool isCompleteTree(TreeNode *root) {
      4         queue<TreeNode *> q;
      5         int had_empty = 0;
      6         q.push(root);
      7         while (!q.empty()) {
      8             TreeNode *root = q.front();
      9             q.pop();
     10             if (!root) {
     11                 had_empty = 1;
     12                 continue;
     13             }
     14             if (had_empty) return false;
     15             q.push(root->left);
     16             q.push(root->right);
     17         }
     18         return true;
     19     }
     20 };