zoukankan      html  css  js  c++  java
  • 104.Maximum Depth of Binary Tree

    class Solution {
    public:
        int maxDepth(TreeNode* root) {
            if (!root) return 0;
            return 1 + max(maxDepth(root->left), maxDepth(root->right));
        }
    };
    
    class Solution {
    public:
        int maxDepth(TreeNode* root) {
            if (!root) return 0;
            int res = 0;
            queue<TreeNode*> q{{root}};
            while (!q.empty()) {
                ++res;
                for (int i = q.size(); i > 0; --i) {
                    TreeNode *t = q.front(); q.pop();
                    if (t->left) q.push(t->left);
                    if (t->right) q.push(t->right);
                }
            }
            return res;
        }
    };
    
  • 相关阅读:
    tzselect
    tzfile
    ttytype
    tty
    TRUNCATE
    true
    troff
    touch
    Open vSwitch
    Web 在线文件管理器学习笔记与总结(5)修改文件内容
  • 原文地址:https://www.cnblogs.com/smallredness/p/10676748.html
Copyright © 2011-2022 走看看