leetcode

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

0104.cpp (480B)


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