This commit is contained in:
Ivan Li 2019-01-08 14:46:18 +08:00
parent f8349a0098
commit 7d8e5c7819

View File

@ -129,18 +129,18 @@ class BinarySearchTree(var root: Option[Node[Int]]) extends BinaryTree[Int] {
}
def hight(): Int = {
_hight(root)
def height(): Int = {
_height(root)
}
private[this] def _hight(nodeOpt: Option[Node[Int]]): Int = {
private[this] def _height(nodeOpt: Option[Node[Int]]): Int = {
nodeOpt match {
case None => 0
case Some(node) => {
if (node.left.isEmpty && node.right.isEmpty) {
1
} else {
scala.math.max(_hight(node.left), _hight(node.right)) + 1
scala.math.max(_height(node.left), _height(node.right)) + 1
}
}
}