LeetCode 104. Maximum Depth of Binary Tree(二叉树高度)
来源:互联网 发布:在淘宝点击卖家没反应 编辑:程序博客网 时间:2024/06/05 10:54
原题网址:https://leetcode.com/problems/maximum-depth-of-binary-tree/
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; } * } */public class Solution { private int max = 0; private void check(TreeNode root, int depth) { if (root == null) return; if (root.left == null && root.right == null) { max = Math.max(max, depth); return; } if (root.left != null) check(root.left, depth+1); if (root.right != null) check(root.right, depth+1); } public int maxDepth(TreeNode root) { max = 0; check(root, 1); return max; }}
0 0
- LeetCode 104. Maximum Depth of Binary Tree(二叉树高度)
- Leetcode 104. Maximum Depth of Binary Tree 二叉树的最大高度 解题报告
- LeetCode 二叉树 | 104. Maximum Depth of Binary Tree
- Leetcode - Tree - 104. Maximum Depth of Binary Tree(DFS求二叉树最深深度)
- Maximum Depth of Binary Tree 求二叉树的高度/深度 @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】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] 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
- Spring概括总结
- leetcode #23 in cpp
- Leetcode 130. Surrounded Regions
- LeetCode 102. Binary Tree Level Order Traversal(二叉树分层遍历)
- LeetCode 103. Binary Tree Zigzag Level Order Traversal(二叉树之字形遍历)
- LeetCode 104. Maximum Depth of Binary Tree(二叉树高度)
- LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal(从前序遍历和中序遍历构造二叉树)
- LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal(根据中序遍历和后序遍历构造二叉树)
- LeetCode 107. Binary Tree Level Order Traversal II(二叉树分层遍历)
- LeetCode 108. Convert Sorted Array to Binary Search Tree(数组转换为二叉搜索树)
- LeetCode 109. Convert Sorted List to Binary Search Tree(链表到二叉搜索树)
- leetcode #24 in cpp
- Leetcode 133. Clone Graph & 138. Copy List with Random Pointer
- LeetCode 110. Balanced Binary Tree(平衡二叉树)