十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
深度:

網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序開發(fā)、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了普安免費建站歡迎大家使用!
int length(BiTree t)
{
int depth2 = 0;
int depth3 = 0;
if(t == null ) return 0;
//右子樹的深度
depth2 = length(t.right);
//左子樹的深度
depth3 = length(t.left);
if(depth2>depth3)
return depth2+1;
else
return depth3+1;
}寬度:
int getMaxWidth(TreeNode root)
{
if (root == null)
return 0;
Queue queue = new ArrayDeque();
int maxWitdth = 1; // 最大寬度
queue.add(root); // 入隊
while (true)
{
int len = queue.size(); // 當(dāng)前層的節(jié)點個數(shù)
if (len == 0)
break;
while (len > 0)
{
// 如果當(dāng)前層,還有節(jié)點
TreeNode t = queue.pop();
len--;
if (t.left != null)
queue.push(t.left); // 下一層節(jié)點入隊
if (t.right != null)
queue.add(t.right);// 下一層節(jié)點入隊
}
maxWitdth = Math.max(maxWitdth, queue.size());
}
return maxWitdth;
}