首页 > TAG信息列表 > getDp

110.balanced-binary-tree 平衡二叉树

获取左右子树的高度,如果左右子树高度差小于等于1,则判断左右子树的左右子树,如此递归下去。 class Solution { public: int getDp(TreeNode *root) { if (root == nullptr) return 0; int ldp = getDp(root->left); int rdp = getDp(root

222.count-complete-tree-nodes 完全二叉树的节点个数

遍历法 遍历所有节点的方法,时间复杂度为\(O(n)\) class Solution { public: int countNodes(TreeNode *root) { if (root == nullptr) return 0; int lc = countNodes(root->left); int rc = countNodes(root->right); return