[LeetCode]Maximum Depth of Binary Tree做题笔记
来源:互联网 发布:akko ducky one 87知乎 编辑:程序博客网 时间:2024/06/03 18:29
题意:给出一棵二叉树,求出树的深度
分析:这个一个基础题,数据结构的课本里都有解法了,树的深度定义:root节点depth为1,以此类推,子树的depth以1为步长,累加即可
代码:以递归的方式实现
int maxDepth(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function if(root == NULL) return 0; else { int leftdepth = maxDepth(root->left); int rightdepth = maxDepth(root->right); int max = leftdepth > rightdepth ? leftdepth : rightdepth; return 1 + max; } }
- [LeetCode]Maximum Depth of Binary Tree做题笔记
- leetcode笔记:Maximum Depth of Binary Tree
- Leetcode - Tree - Maximum Depth of Binary Tree
- [leetcode][tree] Maximum Depth of Binary Tree
- LeetCode题目笔记(二) -- Maximum Depth of Binary Tree
- LeetCode笔记:104.Maximum Depth of Binary Tree
- LeetCode Maximum Depth of Binary Tree
- [Leetcode] Maximum Depth of Binary Tree
- leetcode 24: Maximum Depth of Binary Tree
- [LeetCode] Maximum Depth of Binary Tree
- Leetcode 104 Maximum Depth of Binary Tree
- 【leetcode】Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- [LeetCode]Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- Leetcode: Maximum Depth of Binary Tree
- LeetCode-Maximum Depth of Binary Tree
- [leetcode] Maximum Depth of Binary Tree
- MySQL Replication
- 泛型 Map集合(day18)
- JavaScript加强之自定义event
- C#将数据集连接到Excel并显示
- android ListView几个比较特别的属性
- [LeetCode]Maximum Depth of Binary Tree做题笔记
- makefile编译选项
- LDR指令详解
- 几种冒泡(起泡)排序的总结
- IOS 开发学习指南及blog目录
- windbg 如何再内核模式调试用户空间的程序
- TreeViewer双击展开树的孩子结点
- Spring MVC学习---JSON转换功能(启动Spring MVC的注解功能,完成请求和注解POJO的映射)
- python 实现将网站添加到桌面快捷方式