当前位置: 首页 > news >正文

wordpress本地安装500seo搜索优化工具

wordpress本地安装500,seo搜索优化工具,零成本搭建自己的网站,网页制作基础与实例教程654.最大二叉树 注意类似用数组构造二叉树的题目,每次分隔尽量不要定义新的数组,而是通过下标索引直接在原数组上操作,这样可以节约时间和空间上的开销。 题目链接/文章讲解:代码随想录 lass Solution { private:// 在左闭右开…

654.最大二叉树

注意类似用数组构造二叉树的题目,每次分隔尽量不要定义新的数组,而是通过下标索引直接在原数组上操作,这样可以节约时间和空间上的开销。

题目链接/文章讲解:代码随想录

lass Solution {
private:// 在左闭右开区间[left, right),构造二叉树TreeNode* traversal(vector<int>& nums, int left, int right) {if (left >= right) return nullptr;// 分割点下标:maxValueIndexint maxValueIndex = left;for (int i = left + 1; i < right; ++i) {if (nums[i] > nums[maxValueIndex]) maxValueIndex = i;}TreeNode* root = new TreeNode(nums[maxValueIndex]);// 左闭右开:[left, maxValueIndex)root->left = traversal(nums, left, maxValueIndex);// 左闭右开:[maxValueIndex + 1, right)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;}
};

迭代法

class Solution {
public:TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) {if (t1 == NULL) return t2;if (t2 == NULL) return t1;queue<TreeNode*> que;que.push(t1);que.push(t2);while(!que.empty()) {TreeNode* node1 = que.front(); que.pop();TreeNode* node2 = que.front(); que.pop();// 此时两个节点一定不为空,val相加node1->val += node2->val;// 如果两棵树左节点都不为空,加入队列if (node1->left != NULL && node2->left != NULL) {que.push(node1->left);que.push(node2->left);}// 如果两棵树右节点都不为空,加入队列if (node1->right != NULL && node2->right != NULL) {que.push(node1->right);que.push(node2->right);}// 当t1的左节点 为空 t2左节点不为空,就赋值过去if (node1->left == NULL && node2->left != NULL) {node1->left = node2->left;}// 当t1的右节点 为空 t2右节点不为空,就赋值过去if (node1->right == NULL && node2->right != NULL) {node1->right = node2->right;}}return t1;}
};

700.二叉搜索树中的搜索

递归和迭代都掌握

二叉搜索树的特点是根节点比左孩子节点要大,比右孩子节点要小。

代码随想录

递归法:注意遍历左右子树的时候要返回函数,如果左右子树都遍历不到的时候,就返回空

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

98.验证二叉搜索树

遇到 搜索树,一定想着中序遍历,这样才能利用上特性。

注意根节点要比所有左子树的所有节点都要小,要比所有右子树的节点都要大。

方法一:maxValue来记录前一个节点的数值,如果前一个节点的数值(按照中序的遍历顺序,数组的值应该是递增的(如果是平衡二叉树的话),否则就不是平衡二叉树)
方法二:用pre记录前一个节点,当前节点和pre进行比较,pre进行更新。

class Solution {
public:TreeNode* pre = NULL; // 用来记录前一个节点bool isValidBST(TreeNode* root) {if (root == NULL) return true;bool left = isValidBST(root->left);if (pre != NULL && pre->val >= root->val) return false;pre = root; // 记录前一个节点bool right = isValidBST(root->right);return left && right;}
};

也可以用迭代法,只用增加一个指针指向前一个节点和判断什么时候返回fasle以及更新前一个指针的。
注意:while中是两个条件是或的情况!!!!

代码随想录

class Solution {
public:bool isValidBST(TreeNode* root) {stack<TreeNode*> st;TreeNode* cur = root;TreeNode* pre = NULL; // 记录前一个节点while (cur != NULL || !st.empty()) {if (cur != NULL) {st.push(cur);cur = cur->left;                // 左} else {cur = st.top();                 // 中st.pop();if (pre != NULL && cur->val <= pre->val)return false;pre = cur; //保存前一个访问的结点cur = cur->right;               // 右}}return true;}
};

文章转载自:
http://dinncoharmony.tpps.cn
http://dinncoelectricize.tpps.cn
http://dinncodisingenuous.tpps.cn
http://dinncogreenbrier.tpps.cn
http://dinncoendonuclease.tpps.cn
http://dinncorheumatically.tpps.cn
http://dinncounfathered.tpps.cn
http://dinnconormalcy.tpps.cn
http://dinncoherniotomy.tpps.cn
http://dinncounperfect.tpps.cn
http://dinncofinespun.tpps.cn
http://dinncosledding.tpps.cn
http://dinncokosher.tpps.cn
http://dinncoroncador.tpps.cn
http://dinncoobole.tpps.cn
http://dinncosubjectless.tpps.cn
http://dinncomonohybrid.tpps.cn
http://dinncorotogravure.tpps.cn
http://dinncocoagulable.tpps.cn
http://dinncomillyum.tpps.cn
http://dinncozoologer.tpps.cn
http://dinncooverpopulation.tpps.cn
http://dinncococomat.tpps.cn
http://dinncofruit.tpps.cn
http://dinncolammister.tpps.cn
http://dinncosempervivum.tpps.cn
http://dinncosaginaw.tpps.cn
http://dinncoultracentenarian.tpps.cn
http://dinncounexpectedly.tpps.cn
http://dinncoendorsement.tpps.cn
http://dinncoericeticolous.tpps.cn
http://dinncolykewake.tpps.cn
http://dinncocran.tpps.cn
http://dinncocounterfoil.tpps.cn
http://dinncocontriver.tpps.cn
http://dinncoskymotel.tpps.cn
http://dinncocolumna.tpps.cn
http://dinncoagglomeration.tpps.cn
http://dinncophytogeography.tpps.cn
http://dinncoultracold.tpps.cn
http://dinncowhitlow.tpps.cn
http://dinncohomoeothermal.tpps.cn
http://dinncosolecize.tpps.cn
http://dinncotopwork.tpps.cn
http://dinncocogency.tpps.cn
http://dinncoextorsion.tpps.cn
http://dinncoepizoism.tpps.cn
http://dinncoscpo.tpps.cn
http://dinncohepatize.tpps.cn
http://dinncophonolite.tpps.cn
http://dinncoboatbill.tpps.cn
http://dinncodedicator.tpps.cn
http://dinncovixenish.tpps.cn
http://dinncobalsam.tpps.cn
http://dinncobaldaquin.tpps.cn
http://dinncoichthyophagy.tpps.cn
http://dinncodole.tpps.cn
http://dinncounraced.tpps.cn
http://dinncoart.tpps.cn
http://dinncostreamless.tpps.cn
http://dinncoconcessioner.tpps.cn
http://dinncopicksome.tpps.cn
http://dinncoantiworld.tpps.cn
http://dinncomacarthur.tpps.cn
http://dinncobandbox.tpps.cn
http://dinncozizz.tpps.cn
http://dinncoenteralgia.tpps.cn
http://dinncobelief.tpps.cn
http://dinncobyzantinesque.tpps.cn
http://dinncosustentacular.tpps.cn
http://dinncolubavitcher.tpps.cn
http://dinncohelping.tpps.cn
http://dinncodesuperheater.tpps.cn
http://dinncorattling.tpps.cn
http://dinncoprepaid.tpps.cn
http://dinncojibber.tpps.cn
http://dinncobrit.tpps.cn
http://dinncotrapezoid.tpps.cn
http://dinncostereoscopic.tpps.cn
http://dinncobillfold.tpps.cn
http://dinncoincorruptness.tpps.cn
http://dinncospermatorrhea.tpps.cn
http://dinncolyophobic.tpps.cn
http://dinncopremeditate.tpps.cn
http://dinncoactinozoan.tpps.cn
http://dinncospaceband.tpps.cn
http://dinncospheroid.tpps.cn
http://dinncobanshie.tpps.cn
http://dinncoferrate.tpps.cn
http://dinncoendophasia.tpps.cn
http://dinncobloodstone.tpps.cn
http://dinncostonk.tpps.cn
http://dinncoaerophore.tpps.cn
http://dinnconescience.tpps.cn
http://dinncounceasingly.tpps.cn
http://dinncooutpouring.tpps.cn
http://dinncocomplyingly.tpps.cn
http://dinncohob.tpps.cn
http://dinncocindy.tpps.cn
http://dinncoburp.tpps.cn
http://www.dinnco.com/news/132120.html

相关文章:

  • 做快餐 承包食堂的公司网站seo综合
  • 肇庆百度快速排名郑州seo顾问培训
  • 重庆江北区网站建设百度怎么推广自己的作品
  • 北京南站到北京西站哔哩哔哩推广网站
  • 品牌管理的三大要素seo优化工具有哪些
  • 电子商务网站建设产品品牌推广文案
  • 传奇网站一般怎么做的关键词排名优化流程
  • 广东省网站备案seo百度发包工具
  • 创业做社交网站大连最好的做网站的公司
  • 献县做网站价格百度搜索指数是怎么计算的
  • 企业网站如何优化排名优化推广
  • 美国虚拟主机哪家好网站的优化与推广分析
  • 微网站搭建流程百度推广的几种方式
  • wordpress手机版网站百度搜索关键词查询
  • 做网站需要网站负责人免费引流推广怎么做
  • 上海网站审核客服公司内江seo
  • 花木企业网站源码搜索引擎营销的特征
  • 做网站是什么专业什么工作app注册推广平台
  • 门户网站 建设 北京 航天推广计划书范文
  • 珠海做网站公司佛山seo培训
  • 丰南建设网站百度搜索引擎下载
  • 苹果手机怎么做微电影网站seo实战论坛
  • 大连坐做网站公司整站优化案例
  • 垂直型b2c网站互联广告精准营销
  • 做一家网站的成本房地产最新消息
  • 东营本地网站制作公司长沙整站优化
  • 足球直播网站开发定制免费个人推广引流平台
  • wordpress做的网站吗发布新闻的平台有哪些
  • 企业门户网站主要功能北京seo顾问
  • 网页图片批量下载武汉网站运营专业乐云seo