leetcode 110.平衡二叉樹

在第104題中,maxdepth函數實際上遍歷了二叉樹中每個節點的左右子樹的高度,對其稍加修改,當檢查到兩子樹高度差大於1時返回一個特定異常值即可。 bool isBalanced(TreeNode *root) { if (root == nullptr) { return true; } int a = maxDepth_extern(root); if (a ==
相關文章
相關標籤/搜索