LeetCode_111.二叉树的最小深度
生活随笔
收集整理的這篇文章主要介紹了
LeetCode_111.二叉树的最小深度
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題解C
題解Java
/*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode(int x) { val = x; }* }*/ class Solution {public int minDepth(TreeNode root) {if(root==null){return 0;}if((root.left==null) && (root.right==null)){return 1;}int min_depth = Integer.MAX_VALUE;if(root.left!=null){min_depth = Math.min(minDepth(root.left),min_depth);}if(root.right!=null){min_depth = Math.min(minDepth(root.right),min_depth);}return min_depth + 1;} }相關(guān)知識
Integer.MAZ_VALUE:表示int所能表示的最大值0x7fffffff
相對應的Integer.MIN_VALUE:表示int所能表示的最小值0x80000000
總結(jié)
以上是生活随笔為你收集整理的LeetCode_111.二叉树的最小深度的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode_226.翻转二叉树
- 下一篇: LeetCode_97.交错字符串_没懂