## 20240311-算法复习打卡day20||● 654.最大二叉树 ● 617.合并二叉树 ● 700.二叉搜索树中的搜索 ● 98.验证二叉搜索树

news/2024/5/26 20:57:54/文章来源:https://blog.csdn.net/qq_52784762/article/details/136618165

● 654.最大二叉树

``````class Solution {
private:TreeNode* traversal(vector<int>& nums, int left, int right) {if (left >= right) return NULL;int maxValueIndex = left;for (int i = left + 1; i < right; ++i) {if (nums[i] > nums[maxValueIndex]) maxValueIndex = i;}TreeNode* root = new TreeNode(nums[maxValueIndex]);root->left = traversal(nums, left, maxValueIndex);root->right = traversal(nums, maxValueIndex + 1, right);return root;}
public:TreeNode* constructMaximumBinaryTree(vector<int>& nums) {return traversal(nums, 0, nums.size());}
};``````

● 617.合并二叉树

``````class Solution {
public:TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) {if (t1 == NULL) return t2;if (t2 == NULL) return t1;TreeNode* root = new TreeNode(0);root->val = t1->val + t2->val;root->left = mergeTrees(t1->left, t2->left);root->right = mergeTrees(t1->right, t2->right);return root;}
};``````

● 700.二叉搜索树中的搜索

``````class Solution {
public:TreeNode* searchBST(TreeNode* root, int val) {if (root == NULL || root->val == val) return root;TreeNode* result = NULL;if (root->val > val) result = searchBST(root->left, val);if (root->val < val) result = searchBST(root->right, val);return result;}
};``````

● 98.验证二叉搜索树

``````class Solution {
private:vector<int> vec;void traversal(TreeNode* root) {if (root == NULL) return;traversal(root->left);vec.push_back(root->val);traversal(root->right);}public:bool isValidBST(TreeNode* root) {vec.clear();traversal(root);for (int i = 1; i < vec.size(); i++) {if (vec[i] <= vec[i - 1]) return false;}return true;}
};``````

### 2024Python二级

1. 2. 前序遍历首先访问根节点再访问左子树和右子树 3. 4. sub不属于保留字 5. 6. 7. 8. continue是再重新开始进行循环&#xff0c;不是题目中所规定字母的话就对它进行输出 9. Python没有主函数的说法 10. 未转化为数据所要求的形式&#xff0c;应首先考虑eval 11. l…

### 部署docker仓库harbor

1、下载包 1、包已上传有两个harbor.v2.6.0.tar与harbor.tar 2、harbor.tar解压后会生成harbor目录&#xff0c;将harbor.v2.6.0.tar移动到harbor目录下。 3、执行harbor目录下的install.sh 4、执行完后修改配置文件 2、修改配置文件 vim /root/harbor/make/ harbor.yml.tmpl …

### Kotlin/Java重写equals后==表现（2）

Kotlin/Java重写equals后表现&#xff08;2&#xff09; 如果不重写默认的equals方法&#xff0c;即使用Object默认的equals()方法&#xff0c;而Object默认的equals方法&#xff0c;其实比较两个对象的地址&#xff1a; fun main(args: Array<String>) {val u1 User(&…