class Solution:
    def count_nodes(self, node):
        if not node:
            return 0
        
        left_depth, right_depth = self.get_depth(node.left), self.get_depth(node.right)

        if left_depth == right_depth:
            #left side is complete
            return 2 ** (left_depth) + self.count_nodes(node.right)
        else:
            # right side is complete
            return 2 ** (right_depth) + self.count_nodes(node.left)
    
    def get_depth(self, node):
        depth = 0
        while node:
            depth += 1
            node = node.left
        
        return depth
    

