随笔分类 -  二叉树

摘要:图解找递推公式 const int N = 20; class Solution { public: int dp[N]; int numTrees(int n) { dp[0] = 1; for (int i = 1; i <= n; i ++) for (int j = 0; j <= i - 阅读全文
posted @ 2022-09-26 09:32 hjy94wo 阅读(11) 评论(0) 推荐(0) 编辑
摘要:二叉搜索树 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值; 若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值; 它的左、右子树也分别为二叉搜索树 /** * Definition for a binary tree node. * struct TreeNode { * 阅读全文
posted @ 2022-09-26 09:09 hjy94wo 阅读(13) 评论(0) 推荐(0) 编辑
摘要:后序遍历 class Solution { public: int dfs(TreeNode* node) { if (node == nullptr) return 0; if (node->left == nullptr && node->right != nullptr) { return 1 阅读全文
posted @ 2022-09-07 09:50 hjy94wo 阅读(13) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int maxDepth(Node* root) { if (root == nullptr) return 0; int depth = 0; for (int i = 0; i < root->children.size(); i ++) { d 阅读全文
posted @ 2022-09-07 09:26 hjy94wo 阅读(13) 评论(0) 推荐(0) 编辑
摘要:前序遍历解法 前序遍历求二叉树深度 class Solution { public: int res = 0; void dfs(TreeNode* root, int depth) { res = res > depth ? res : depth; if (root->left == nullp 阅读全文
posted @ 2022-09-07 09:25 hjy94wo 阅读(15) 评论(0) 推荐(0) 编辑
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), rig 阅读全文
posted @ 2022-09-07 08:54 hjy94wo 阅读(6) 评论(0) 推荐(0) 编辑
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), rig 阅读全文
posted @ 2022-09-07 08:38 hjy94wo 阅读(16) 评论(0) 推荐(0) 编辑
摘要:二叉树种类 满二叉树 完全二叉树(底层连续) 二叉搜索树(节点元素有一定顺序) 平衡二叉搜索树(左子树与右子树高度差绝对值小于) 存储方式 链式存储 线式存储 二叉树的遍历 深度优先遍历 前序遍历 中左右 中序遍历 左中右 后序遍历 左右中 广度优先遍历 层序遍历 迭代法 LeetCode 144 阅读全文
posted @ 2022-09-06 14:59 hjy94wo 阅读(23) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示