104. Maximum Depth of Binary Tree
来源:互联网 发布:mongodb是什么数据库 编辑:程序博客网 时间:2024/05/22 11:50
递归形式
int maxDepth(TreeNode* root) { if(!root) return 0; return 1+max(maxDepth(root->left),maxDepth(root->right)); }
使用BFS
int maxDepth(TreeNode* root) { if(!root) return 0; int res=0; queue<TreeNode*> q; q.push(root); while(!q.empty()){ res++; int n=q.size(); for(int i=0;i<n;i++){ TreeNode* t=q.front();q.pop(); if(t->left) q.push(t->left); if(t->right) q.push(t->right); } } return res; }
阅读全文
0 0
- [LeetCode]104.Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 【LeetCode】104.Maximum Depth of Binary Tree
- [Leetcode] 104. Maximum Depth of Binary Tree
- LeetCode --- 104. Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- leetCode 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree LeetCode
- 104. Maximum Depth of Binary Tree LeetCode
- 104. Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- leetcode:104. Maximum Depth of Binary Tree
- Dubbo常用标签
- 路由——route(2)
- Duan2baka的AC自动机模板!
- react踩坑不完全指北(2)
- 1.CountDownLatch简介
- 104. Maximum Depth of Binary Tree
- 二.PullToRefresh 主方法里面
- caffe画 feature map
- 深吸一口奶茶,领取个京东云免费VPS
- 团队项目负责人的一些感悟
- 17.12.13,web学习第二十五天,还有一年,努力吧青年动态代理
- sm(spring+mybatis)注释版的整合
- 递归法查找特定后缀或关键字文件返
- 程序设计与算法(一)C语言程序设计CAP 第一周