You are viewing a single comment's thread. Return to all comments →
Using Python 3’s pattern-matching:
def getHeight(self, root): match root: case Node(left=None, right=None): return 0 case Node(left=None): return 1 + self.getHeight(root.right) case Node(right=None): return 1 + self.getHeight(root.left) case _: return max(1 + self.getHeight(root.left), 1 + self.getHeight(root.right))
Seems like cookies are disabled on this browser, please enable them to open this website
Day 22: Binary Search Trees
You are viewing a single comment's thread. Return to all comments →
Using Python 3’s pattern-matching: