摘要: 后序遍历 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 阅读(17) 评论(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 阅读(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: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)
摘要: 二叉树种类 满二叉树 完全二叉树(底层连续) 二叉搜索树(节点元素有一定顺序) 平衡二叉搜索树(左子树与右子树高度差绝对值小于) 存储方式 链式存储 线式存储 二叉树的遍历 深度优先遍历 前序遍历 中左右 中序遍历 左中右 后序遍历 左右中 广度优先遍历 层序遍历 迭代法 LeetCode 144 阅读全文
posted @ 2022-09-06 14:59 hjy94wo 阅读(29) 评论(0) 推荐(0)
摘要: class Solution { public: int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) { unordered_map<int, int> ma 阅读全文
posted @ 2022-09-06 09:35 hjy94wo 阅读(12) 评论(0) 推荐(0)
摘要: class Solution { public: vector<vector<int>> fourSum(vector<int>& nums, int target) { vector<vector<int>> res; sort(nums.begin(), nums.end()); for (in 阅读全文
posted @ 2022-09-06 09:27 hjy94wo 阅读(16) 评论(0) 推荐(0)
摘要: class Solution { public: bool canConstruct(string ransomNote, string magazine) { int record[26] ={0}; //默认值为0 if (magazine.size() < ransomNote.size()) 阅读全文
posted @ 2022-09-05 18:18 hjy94wo 阅读(12) 评论(0) 推荐(0)
摘要: class Solution { public: vector<vector<int>> res; vector<vector<int>> threeSum(vector<int>& nums) { sort(nums.begin(), nums.end()); for (int i = 0; i 阅读全文
posted @ 2022-09-05 18:02 hjy94wo 阅读(26) 评论(0) 推荐(0)