classSolution { public: intmaxDepth(TreeNode* root){ int depth = 0; queue<TreeNode*> qe; if (root) qe.push(root); while (!qe.empty()) { int node_num = qe.size(); for (int i = 0; i < node_num; i++) { auto tmp = qe.front(); qe.pop();
if (tmp->left) qe.push(tmp->left); if (tmp->right) qe.push(tmp->right); } ++depth; }