深度优先遍历
二叉树的深度
http://www.nowcoder.com/questionTerminal/435fb86331474282a3499955f0a41e8b
JavaScript:
function TreeDepth(pRoot, long = 0) { if(!pRoot){ return long } return Math.max(TreeDepth(pRoot.left, long+1), TreeDepth(pRoot.right, long+1)) }
二叉树的深度
http://www.nowcoder.com/questionTerminal/435fb86331474282a3499955f0a41e8b
JavaScript:
function TreeDepth(pRoot, long = 0) { if(!pRoot){ return long } return Math.max(TreeDepth(pRoot.left, long+1), TreeDepth(pRoot.right, long+1)) }
相关推荐