摘要: 后序遍历 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 阅读(17) 评论(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 阅读(18) 评论(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 阅读(19) 评论(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 阅读(18) 评论(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 阅读(19) 评论(0) 推荐(0)