leetcode 104. Maximum Depth of Binary Tree(C语言数据结构,二叉树的深度,递归)30
来源:互联网 发布:淘宝收购饿了么 编辑:程序博客网 时间:2024/06/05 20:05
贴原题:
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
解析:
本题是要求二叉树的深度。这应该算是数据结构最基础的题目了。
C代码:
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */int maxDepth(struct TreeNode* root) { int l_depth=0, r_depth=0; if(root!=NULL)//根节点非空则继续向下遍历 { l_depth=maxDepth(root->left)+1;//深度+1 r_depth=maxDepth(root->right)+1; } return l_depth>r_depth?l_depth:r_depth;//取左右最大值}
阅读全文
0 0
- leetcode 104. Maximum Depth of Binary Tree(C语言数据结构,二叉树的深度,递归)30
- [leetcode]Maximum Depth of Binary Tree (求二叉树的最大深度 C语言)
- leetcode-104. Maximum Depth of Binary Tree 二叉树的深度,递归,结点结构体
- Leetcode 104.Maximum Depth of Binary Tree (二叉树的最大深度)
- 104. Maximum Depth of Binary Tree | 二叉树的深度
- 【LeetCode笔记】Maximum Depth of Binary Tree 二叉树最大深度 递归&非递归
- 104.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]104. Maximum Depth of Binary Tree--二叉树的最大深度
- Leetcode#104. Maximum Depth of Binary Tree(最大二叉树的深度)
- LeetCode | Maximum Depth of Binary Tree(二叉树的深度)
- LeetCode OJ 之 Maximum Depth of Binary Tree (二叉树的最大深度)
- leetcode系列(28)Maximum Depth of Binary Tree 求二叉树的最大深度
- LeetCode 104 Maximum Depth of Binary Tree(二叉树的最大深度)
- LeetCode--Maximum Depth of Binary Tree (检索二叉树的最大深度)Python
- leetCode 104.Maximum Depth of Binary Tree(二叉树最大深度) 解题思路和方法
- UNICODE,GBK,UTF-8区别
- Zabbix3.x安装图解教程
- vistual Studio Code Tips
- Opencv对视频进行目标检测
- MySQL--修改列定义和更名数据表
- leetcode 104. Maximum Depth of Binary Tree(C语言数据结构,二叉树的深度,递归)30
- ShaderForge API
- 简单的日夜模式切换
- Spark内核源码深度剖析:宽依赖与窄依赖深度剖析
- js对象的深浅拷贝
- image的尺寸的适配
- Python-基于数据驱动模式的自动化测试框架搭建的的逐步实现(二)
- C# Aspose.Word 操作word文档【五】
- java开发/10.1-10.3/邓聪