Skip to content

Instantly share code, notes, and snippets.

@zhaoz
Created November 11, 2010 06:16
Show Gist options
  • Save zhaoz/672103 to your computer and use it in GitHub Desktop.
Save zhaoz/672103 to your computer and use it in GitHub Desktop.
closures in python
def getHeight(self, node=None):
maxHeight = [0]
def traverse(node, height):
if not node:
return
height += 1
if height > maxHeight[0]:
maxHeight[0] = height
traverse(node.left, height)
traverse(node.right, height)
if not node:
node = self.root
traverse(node, 0)
return maxHeight[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment