劍指offer55題
阿新 • • 發佈:2017-08-26
err [] ati node package turn algorithm oot 長度
輸入一棵二叉樹,求該樹的深度。從根結點到葉結點依次經過的結點(含根、葉結點)形成樹的一條路徑,最長路徑的長度為樹的深度。
package com.algorithm05; import com.tools.TreeBinaryFunction; import com.tools.TreeNode; public class Algorithm55 { public static int TreeDepth(TreeNode root) { if(root==null) return 0; int left,right; left = TreeDepth(root.left); right = TreeDepth(root.right); return (left>right)?(left+1):(right+1); } public static void main(String[] args) { TreeNode treeNode = new TreeNode(0); TreeBinaryFunction.CreateTreeBinary(treeNode); System.err.println(TreeDepth(treeNode)); } }
劍指offer55題