当前位置:首页 » 区块链知识 » 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-10-20 08:58:16 浏览:973
暗黑破坏神2eth打孔 发布:2025-10-20 08:42:58 浏览:105
BTC和CBT是一样的吗 发布:2025-10-20 08:42:57 浏览:233
华硕trx40Pro供电 发布:2025-10-20 08:33:26 浏览:432
晒人民币编号的朋友圈 发布:2025-10-20 08:25:32 浏览:687
doge格式 发布:2025-10-20 08:02:00 浏览:382
以太坊会爆发吗 发布:2025-10-20 08:01:59 浏览:772
一台比特币矿机的功率 发布:2025-10-20 07:39:24 浏览:925
trx辅助带 发布:2025-10-20 07:35:29 浏览:48
比特币哈希值有多少位 发布:2025-10-20 07:31:20 浏览:633