leetcode数列求和leetcode我最喜欢的Leetcode问题合集
- 计算完整的树节点
lg(N) * lg(N)
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
count = 0
def countNodes(self, root):
\"\"\"
:type root: TreeNode
:rtype: int
\"\"\"
if not root:
return 0
left_depth = self.traverse(root.left)
right_depth = self.traverse(root.right)
if left_depth:
return 2 ** left_depth + self.countNodes(root.right)
暂无评论