当前位置:首页 » 区块链知识 » 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

热点内容
卖eth币手续费多少 发布:2025-06-24 01:49:34 浏览:666
gtx960挖eth 发布:2025-06-24 01:45:14 浏览:336
元宇宙200 发布:2025-06-24 01:32:22 浏览:307
trx4灯光怎么控制 发布:2025-06-24 01:22:13 浏览:726
蚂蚁A3矿机是挖什么币 发布:2025-06-24 00:52:47 浏览:437
和家长合约怎么写 发布:2025-06-24 00:52:19 浏览:248
trx850出售 发布:2025-06-24 00:51:29 浏览:224
区块链内容上链 发布:2025-06-24 00:39:45 浏览:136
这么久没习惯币圈的大起大落 发布:2025-06-24 00:38:58 浏览:95
doge币不用挖矿吗 发布:2025-06-24 00:37:10 浏览:807