1. 首页
  2. 考试认证
  3. 其它
  4. leetcode数列求和 leetcode 我最喜欢的Leetcode问题合集

leetcode数列求和 leetcode 我最喜欢的Leetcode问题合集

上传者: 2024-10-05 03:37:20上传 ZIP文件 3.05KB 热度 4次
leetcode数列求和leetcode我最喜欢的Leetcode问题合集222.计算完整的树节点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 ( ro
下载地址
用户评论