class BinarySearchTree:
def init(self):
self.root = None
def create(self, val):
if self.root == None:
self.root = Node(val)
else:
current = self.root
while True:
if val < current.info:
if current.left:
current = current.left
else:
current.left = Node(val)
break
elif val > current.info:
if current.right:
current = current.right
else:
current.right = Node(val)
break
else:
break
Enter your code here. Read input from STDIN. Print output to STDOUT
'''
class Node:
def init(self,info):
self.info = info
self.left = None
self.right = None
// this is a node of the tree , which contains info as data, left , right
'''
def height(root):
if root is None :
return 0
queue = [(0, root)]
h = 0
while queue :
th, t = queue.pop(0)
h = max(h, th)
if t.left is not None :
lh = th + 1
queue.append((lh, t.left))
if t.right is not None :
rh = th + 1
queue.append((rh, t.right))
return h
나의 풀이
class BinarySearchTree: def init(self): self.root = None
Enter your code here. Read input from STDIN. Print output to STDOUT
''' class Node: def init(self,info): self.info = info
self.left = None
self.right = None
''' def height(root): if root is None : return 0