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