當前位置:首頁 » 區塊鏈知識 » 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