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

熱點內容
上海atm數字貨幣取款機 發布:2025-06-24 04:10:48 瀏覽:594
數字貨幣合約周期 發布:2025-06-24 04:10:14 瀏覽:763
堡壘礦機藏寶圖 發布:2025-06-24 03:00:55 瀏覽:126
賣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