You are viewing a single comment's thread. Return to all comments →
If anyone else is having issues getting the Python solution to work (because of the wrong function being called by the system), I've found a workaround. I created my own tree and took over __main__ and sys.stdin.
def __init__(self, data):
self.data = data
self.left = None
self.right = None
root = None
def add(self, data):
self.root = self._add(self.root, data)
def _add(self, node, data):
if not node:
if data < node.data:
node.left = self._add(node.left, data)
elif data > node.data:
node.right = self._add(node.right, data)
def _getHeight(self, node):
if not node: return -1
return 1 + max(self._getHeight(node.left), self._getHeight(node.right))
if __name__ == '__main__':
tree = BinaryTree()
for place, line in enumerate(sys.stdin):
if place != 0:
This passes all cases.
Very nice, I would indeed appear that the current presentation for python 2 and python 3 are not really what was intended. Pity as it drove me nuts for half an hour trying to figure why they constructed the code like they did-made no sense. Thanks for clearing it up for people.