leetcode

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

0559.cpp (440B)


      1 class Solution {
      2   public:
      3     int maxDepth(Node *root) {
      4         if (!root) return 0;
      5 
      6         int lvl;
      7         queue<Node *> q;
      8         q.push(root);
      9         for (lvl = 0; !q.empty(); lvl++) {
     10             for (int t = q.size(); t > 0; t--) {
     11                 Node *root = q.front();
     12                 q.pop();
     13                 for (Node *c : root->children)
     14                     q.push(c);
     15             }
     16         }
     17         return lvl;
     18     }
     19 };