class Solution(object):
def countNodes(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if not root: return 0
LH=self.getHeight(root.left)
LR=self.getHeight(root.right)
if LH==LR:
return 2**LH+self.countNodes(root.right)
else:
return 2**LR+self.countNodes(root.left)
def getHeight(self,root):
if not root: return 0
count=1
while root.left:
count+=1
root=root.left
return count