Leetcode Minimum Depth of Binary Tree
来源:互联网 发布:linux高级运维 编辑:程序博客网 时间:2024/06/08 09:04
Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
Difficulty: Easy
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public int minDepth(TreeNode root) { if(root == null) return 0; if(root.left == null && root.right == null) return 1; if(root.left == null) return minDepth(root.right) + 1; if(root.right == null) return minDepth(root.left) + 1; return Math.min(minDepth(root.left), minDepth(root.right)) + 1; }}
0 0
- LeetCode: Minimum Depth of Binary Tree
- [Leetcode] Minimum Depth of Binary Tree
- LeetCode : Minimum Depth of Binary Tree
- leetcode 31: Minimum Depth of Binary Tree
- [LeetCode] Minimum Depth of Binary Tree - BFS
- [LeetCode] Minimum Depth of Binary Tree - DFS
- 【leetcode】Minimum Depth of Binary Tree
- LeetCode:Minimum Depth of Binary Tree
- [LeetCode]Minimum Depth of Binary Tree
- [Leetcode]Minimum Depth of Binary Tree
- [leetcode]Minimum Depth of Binary Tree
- Leetcode: Minimum Depth of Binary Tree
- LeetCode-Minimum Depth of Binary Tree
- [leetcode] Minimum Depth of Binary Tree
- LeetCode - Minimum Depth of Binary Tree
- 【Leetcode】Minimum Depth of Binary Tree
- LeetCode | Minimum Depth of Binary Tree
- LeetCode - Minimum Depth of Binary Tree
- CProxyDllMaker : a class to make proxy dll's masm source code
- Design Tic-Tac-Toe
- PKU四日游(信息科学夏令营)
- HDU 5761_2016 Multi-University Training Contest 3
- Leetcode Sum of Two Integers
- Leetcode Minimum Depth of Binary Tree
- Leetcode Word Ladder II
- Leetcode Binary Tree Preorder Traversal
- Leetcode Convert Sorted Array to Binary Search Tree
- Leetcode Missing Number
- Leetcode Fraction to Recurring Decimal
- Leetcode Rotate List
- typhon例子:cs,bufDataset(类似delphi的clientDataset),josn解析器
- java反射覆写toString方法实现输出实体类属性值