leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0559.cpp (440B)
0 class Solution { 1 public: 2 int maxDepth(Node *root) { 3 if (!root) return 0; 4 5 int lvl; 6 queue<Node *> q; 7 q.push(root); 8 for (lvl = 0; !q.empty(); lvl++) { 9 for (int t = q.size(); t > 0; t--) { 10 Node *root = q.front(); 11 q.pop(); 12 for (Node *c : root->children) 13 q.push(c); 14 } 15 } 16 return lvl; 17 } 18 };