Maximum Depth of Binary Tree:二叉树深度
来源:互联网 发布:大野克夫的水平知乎 编辑:程序博客网 时间:2024/05/21 14:55
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.
思路:标准的深度优先遍历,没什么可说的。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { int max = 0; public void dfs(TreeNode n,int depth) { if(n==null) return; max = Math.max(max,depth); dfs(n.left,depth+1); dfs(n.right,depth+1); } public int maxDepth(TreeNode root) { if(root == null) return 0; dfs(root,1); return max; }}
阅读全文
0 0
- 【LeetCode】Maximum Depth of Binary Tree (二叉树最大深度)
- Maximum Depth of Binary Tree--二叉树的深度
- Maximum Depth of Binary Tree 二叉树的最大深度
- Maximum Depth of Binary Tree 二叉树的最大深度
- Leetcode Maximum Depth of Binary Tree 二叉树最大深度
- 104.Maximum Depth of Binary Tree(二叉树深度)
- Maximum Depth of Binary Tree 二叉树的最大深度
- Maximum Depth of Binary Tree 二叉树的最大深度
- maximum-depth-of-binary-tree(二叉树的最大深度)
- 104. Maximum Depth of Binary Tree | 二叉树的深度
- Maximum Depth of Binary Tree:二叉树深度
- 【二叉树】计算二叉树深度【104. Maximum Depth of Binary Tree】【111. Minimum Depth of Binary Tree】
- [leetcode]Maximum Depth of Binary Tree(二叉树最大深度、Depth-first search)
- leetcode:Maximum Depth of Binary Tree(计算二叉树深度) 【面试算法】
- Maximum Depth of Binary Tree 求二叉树的高度/深度 @LeetCode
- 求二叉树的最大深度 Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree 二叉树的最大深度(重)
- LeetCode | Maximum Depth of Binary Tree(二叉树的深度)
- 学习笔记(二)
- 技术框架部分面试题
- 视图与表的区别
- leetcode编程记录18 #59 Spiral Matrix II
- MAC算法总结
- Maximum Depth of Binary Tree:二叉树深度
- JQuery dataTable Java后台实用教程总结
- IDEA安装及完美破解
- leetCode#226. Invert Binary Tree
- 《软件测试的艺术(原书第2版)》【PDF】下载
- 如何按自定义的坐标点生成随机抽样
- 利用TCP实现多客户聊天系统
- springMVC入门(五)URI Builder
- leetcode 657. Judge Route Circle