class Solution {
public:
int calculateDepth(TreeNode* root) {
int i = 0;
if(!root) return i;
queue<TreeNode*> q;
q.push(root);
while(!q.empty())
{
for(int j = q.size();j>0;j--)
{
TreeNode* tmp = q.front();
q.pop();
if(tmp->left) q.push(tmp->left);
if(tmp->right) q.push(tmp->right);
}
i++;
}
return i;
}
};
leetcode每日一题第七十七天
2024-05-13 21:04:09 32 阅读