leetcode每日一题第七十七天

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;

    }
};

相关推荐

  1. LeetCode

    2024-05-13 21:04:09       52 阅读
  2. 每日 期 洛谷 统计子矩阵

    2024-05-13 21:04:09       23 阅读
  3. 每日 九期 Codeforces Global Round 25

    2024-05-13 21:04:09       22 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-13 21:04:09       5 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-13 21:04:09       5 阅读
  3. 在Django里面运行非项目文件

    2024-05-13 21:04:09       4 阅读
  4. Python语言-面向对象

    2024-05-13 21:04:09       6 阅读

热门阅读

  1. Harmony 添加library依赖库步骤

    2024-05-13 21:04:09       18 阅读
  2. Spring+Mybatis-plus 实现 Gauss DB数据库代码生成

    2024-05-13 21:04:09       14 阅读
  3. puppyteer

    2024-05-13 21:04:09       18 阅读
  4. 力扣:738. 单调递增的数字

    2024-05-13 21:04:09       21 阅读
  5. 访问者模式:设计模式中的动态行为扩展

    2024-05-13 21:04:09       23 阅读
  6. SQL简介

    2024-05-13 21:04:09       20 阅读
  7. vue 自定义事件和子组件方法调用

    2024-05-13 21:04:09       13 阅读
  8. 处理Git将本地大文件上传到公共区域失败

    2024-05-13 21:04:09       21 阅读
  9. 通过实例学C#之Stack类

    2024-05-13 21:04:09       18 阅读
  10. SQLZOO:Self join

    2024-05-13 21:04:09       21 阅读