ICode9

精准搜索请尝试: 精确搜索
  • 110.balanced-binary-tree 平衡二叉树2022-08-28 18:31:47

    获取左右子树的高度,如果左右子树高度差小于等于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 完全二叉树的节点个数2022-08-27 20:04:36

    遍历法 遍历所有节点的方法,时间复杂度为\(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

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有