A utility function to check if a given node is leaf or not
def isLeaf ( node ) : NEW_LINE INDENT if node is None : NEW_LINE INDENT return False NEW_LINE DEDENT if node . left is None and node . right is None : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT