各位大佬,上面那棵树的高度是多少?它的3对吗?
我老师设计的测试用例期望它是2。
这是我用来获取高度的代码;
public int height(TreeNode t){
if (t == null)
return 0;
int heightLeft = height(t.leftChild);
int heightRight = height(t.rightChild)
if( heightLeft > heightRight )
return heightLeft +1;
else
return heightRight +1;
}
你为什么要关闭这个线程?