【发布时间】:2020-03-13 14:41:35
【问题描述】:
def depth(self, key):
temp = self.get(key)
current = self.root
depthCount = 0
if temp is None:
return None
if self.root.key is key:
return 0
if current.key < key and (temp.right is not None):
current = current.right
depthCount += 1
depthCount = self.depth(temp.right.key)
if current.key > key and (temp.left is not None):
current = current.left # key < Root Key
depthCount += 1
depthCount = self.depth(temp.left.key)
return depthCount
您好,我正在尝试根据我提供的代码找到深度,但每当我尝试运行它时,它只会给我节点的高度,而不是深度。
【问题讨论】:
标签: python recursion binary-search-tree