Function to get the count of half Nodes in a binary tree
def gethalfCount ( root ) : NEW_LINE INDENT if root == None : NEW_LINE INDENT return 0 NEW_LINE DEDENT res = 0 NEW_LINE if ( root . left == None and root . right != None ) or ( root . left != None and root . right == None ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT res += ( gethalfCount ( root . left ) + gethalfCount ( root . right ) ) NEW_LINE return res NEW_LINE DEDENT