The most beautiful recursive solution (Python)


#1
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)

#2

fails for this test case

[1,2,2,3,3,null,null,4,4]


#3

Yes, but it is beautiful.
LoL