当前位置:首页 » 区块链知识 » maxdeath区块链

maxdeath区块链

发布时间: 2021-07-09 11:20:18

1. 数据结构二叉树题目

class TreeNode{
int val;
//左孩子
TreeNode left;
//右孩子
TreeNode right;
}

二叉树的题目普遍可以用递归和迭代的方式来解

1. 求二叉树的最大深度

int maxDeath(TreeNode node){
if(node==null){
return 0;
}
int left = maxDeath(node.left);
int right = maxDeath(node.right);
return Math.max(left,right) + 1;
}

2. 求二叉树的最小深度

int getMinDepth(TreeNode root){
if(root == null){
return 0;
}
return getMin(root);
}
int getMin(TreeNode root){
if(root == null){
return Integer.MAX_VALUE;
}
if(root.left == null&&root.right == null){
return 1;
}
return Math.min(getMin(root.left),getMin(root.right)) + 1;
}

3. 求二叉树中节点的个数

int numOfTreeNode(TreeNode root){
if(root == null){
return 0;
}
int left = numOfTreeNode(root.left);
int right = numOfTreeNode(ro

热点内容
btc会变成纪念币吗 发布:2025-09-11 22:05:14 浏览:450
比特币套现换算 发布:2025-09-11 21:58:44 浏览:794
如何冻结以太坊的地址 发布:2025-09-11 21:58:34 浏览:590
区块链与建筑工程管理 发布:2025-09-11 21:49:19 浏览:703
比特币今年赚多少钱一个 发布:2025-09-11 21:45:05 浏览:682
eth以太坊怎么换人民币 发布:2025-09-11 21:24:31 浏览:254
2018澳门万人区块链大会 发布:2025-09-11 20:29:31 浏览:219
矿机伪造share 发布:2025-09-11 20:12:01 浏览:884
去番禺中心医院坐什么公交车站 发布:2025-09-11 19:28:21 浏览:195
斐讯区块链羊毛 发布:2025-09-11 18:24:39 浏览:26