The most beautiful recursive solution (Python)

class Solution:
    # @param A : root node of tree
    # @return an integer
    def isBalanced(self, A):
        if not A:
            return 1
        if not A.left and not A.right:
            return 1
        if A.left and not A.right:
            if A.left.left or A.left.right:
                return 0
        if A.right and not A.left:
            if A.right.left or A.right.right:
                return 0
        return self.isBalanced(A.left) and self.isBalanced(A.right)


fails for this test case



Yes, but it is beautiful.