首页 > 其他分享 >leetcode222-完全二叉树的节点个数

leetcode222-完全二叉树的节点个数

时间:2022-08-25 20:02:21浏览次数:115  
标签:leetcode222 个数 二叉树 countNodes root 节点

完全二叉树的节点个数

  • 递归
class Solution {
    public int countNodes(TreeNode root) {
        if(root == null)    return 0;
        return countNodes(root.left)+countNodes(root.right)+1;
    }
}

标签:leetcode222,个数,二叉树,countNodes,root,节点
From: https://www.cnblogs.com/xzh-yyds/p/16625529.html

相关文章

  • KubeSphere3.3 私有云部署,在linux上 多节点安装
    在四台主机上部署(也可在虚拟机部署) 使用软件版本Centos7.9内核3.10.0-1160.el7.x86_64 KubeSphere3.3 KubeSphere官网 面向云原生应用的容器混合云,支持Kub......
  • 平衡二叉树(AVL)的实现
    平衡二叉树概念平衡二叉排序树(BalancedBinaryTree),因由前苏联数学家Adelson-Velskii和Landis于1962年首先提出的,所以又称为AVL树。平衡二叉树是一种特殊的二叉排序......
  • LCA C 求和 求子树权值和 树上节点单点修改 dfs序+树状数组
     链接:https://ac.nowcoder.com/acm/problem/204871来源:牛客网题目描述已知有 nnn个节点,有 n−1n-1n−1条边,形成一个树的结构。给......
  • 二叉树的结构
    https://www.acwing.com/problem/content/description/4274/#include<bits/stdc++.h>#include<string.h>usingnamespacestd;constintN=1010;intpost[N],in[N......
  • 判断是不是平衡二叉树
    staticintflag=0;publicbooleanisBalanced(TreeNoderoot){flag=0;travel12(root);if(flag==1){returnfalse;......
  • LeetCode 24. 两两交换链表中的节点
    /***Definitionforsingly-linkedlist.*structListNode{*intval;*ListNode*next;*ListNode():val(0),next(nullptr){}*List......
  • leetcode 热题100刷题-二叉树的中序遍历
    题题号:94题目:二叉树的中序遍历难度:简单链接:https://leetcode.cn/problems/binary-tree-inorder-traversal/2022/08/23答案算法思路  本题在课程中是学过的。  ......
  • nebula 查询节点数、边数
    SHOWSTATS-NebulaGraphDatabase手册(nebula-graph.com.cn)1#选择图空间。2nebula>USEbasketballplayer;34#执行SUBMITJOBSTATS。5nebula>SU......
  • 算法:两个链表的第一个公共节点
    问题输入两个链表,找出它们的第一个公共节点。解决//1、暴力解法classSolution{ListNodegetIntersectionNode(ListNodeheadA,ListNodeheadB){w......
  • tidb 驱逐节点leader
    1.检查schedul-limit参数showconfigwheretype='pd'andnamelike'%schedule-limit';schedule.hot-region-schedule-limit 4schedule.leader-schedule-limit 4schedul......