* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
class Solution {
public:
/**
*
* @param root TreeNode类
* @return int整型
*/
int maxDepth(TreeNode* root) {
// write code here
if(!root)
return 0;
int ans=0;
queue<TreeNode *>q;
TreeNode *cur;
q.push(root);
while(!q.empty()){
int n=q.size();
++ans;
for(int i=0;i<n;i++){
cur=q.front();
q.pop();
if(cur->left)
q.push(cur->left);
if(cur->right)
q.push(cur->right);
}
}
return ans;
}
};