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

外贸网站seo优化方案网站建设效果好不好

外贸网站seo优化方案,网站建设效果好不好,网站配置系统,时间管理系统 网站开发给你一个含重复值的二叉搜索树#xff08;BST#xff09;的根节点 root #xff0c;找出并返回 BST 中的所有 众数#xff08;即#xff0c;出现频率最高的元素#xff09;。 如果树中有不止一个众数#xff0c;可以按 任意顺序 返回。 假定 BST 满足如下定义#xf…给你一个含重复值的二叉搜索树BST的根节点 root 找出并返回 BST 中的所有 众数即出现频率最高的元素。 如果树中有不止一个众数可以按 任意顺序 返回。 假定 BST 满足如下定义 结点左子树中所含节点的值 小于等于 当前节点的值结点右子树中所含节点的值 大于等于 当前节点的值左子树和右子树都是二叉搜索树 提示 树中节点的数目在范围 [1, 104] 内 105 Node.val 105 进阶你可以不使用额外的空间吗假设由递归产生的隐式调用栈的开销不被计算在内 AC: /** lc appleetcode.cn id501 langcpp** [501] 二叉搜索树中的众数*/// lc codestart /*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeNode() : val(0), left(nullptr), right(nullptr) {}* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}* };*/ class Solution { public:TreeNode* pre NULL;int count 0;int maxCount 0;vectorint result;void traversal(TreeNode* cur) {if(cur NULL)return ;traversal(cur-left);if(pre NULL)count 1;else if(pre-val cur-val){count;}else count 1;pre cur;if(count maxCount){result.push_back(cur-val);}if(count maxCount){maxCount count;result.clear();result.push_back(cur-val);}traversal(cur-right);return ;}vectorint findMode(TreeNode* root) {traversal(root);return result;} }; // lc codeendTips 对于一次遍历完搜索二叉树将众数结果统计出来 if(count maxCount){result.push_back(cur-val);}if(count maxCount){maxCount count;result.clear();result.push_back(cur-val);}The first if statement checks if the count of the current value is equal to the maximum count seen so far (count maxCount). If the count is equal to the maximum count, then the current value is also a mode of the binary search tree, so the value is added to the result vector using the push_back function. The second if statement checks if the count of the current value is greater than the maximum count seen so far (count maxCount). If the count is greater than the maximum count, then the current value is a new mode of the binary search tree, so the result vector is cleared using the clear function, and the current value is added to the result vector using the push_back function. Additionally, the maxCount variable is updated to reflect the new maximum count. Overall, this block of code is a simple and efficient way to update the result vector with the mode(s) of a binary search tree. The code uses a straightforward approach to keep track of the count of each value in the binary search tree, and updates the result vector whenever a new mode is found. One possible way to improve the code would be to add error checking to ensure that cur is not a null pointer before accessing its value. Additionally, the variable names could be more descriptive to make the code easier to read and understand. 二叉树双指针的移动 pre cur;The line of code pre cur; is used to update the pre pointer to point to the current node cur. This is because the function is traversing the binary search tree in order, and pre needs to point to the previous node in order to calculate the count of each value in the binary search tree. Specifically, the function uses an in-order traversal of the binary search tree to visit each node in ascending order. For each node, the function calculates the count of the node’s value by comparing it to the value of the previous node. If the value is the same as the previous node’s value, then the count is incremented. Otherwise, the count is reset to 1. The pre pointer is used to keep track of the previous node visited during the in-order traversal. Initially, pre is set to nullptr to indicate that there is no previous node. For each node cur, the line of code pre cur; updates pre to point to cur, so that pre will point to the previous node during the next iteration of the loop. Overall, this line of code is a simple and efficient way to update the pre pointer during an in-order traversal of a binary search tree. One possible way to improve the code would be to add error checking to ensure that pre and cur are not null pointers before updating pre. Additionally, the variable names could be more descriptive to make the code easier to read and understand.
http://www.hkea.cn/news/14563876/

相关文章:

  • ui做的好的公司网站上海网页网络技术有限公司
  • 山东建设银行官网网站公众号wordpress同步
  • 中国空间站距离地面多少公里租网络服务器多少钱
  • 石家庄做网站建设的公司哪家好ppt软件手机版免费下载
  • 网站开发合同文档百度官网
  • 西安免费做网站价格网络优化器下载
  • 汾阳做网站的公司网站设计与建设的公司
  • 昆山推广用什么网站比较好网站建设的栏目
  • asp 网站建设教程德阳网站建设推广
  • 什么是网站销售移动宽带续费网上可以续费嘛
  • 灵宝网站制作工作室晋中营销型网站建设
  • 琼海市建设局网站企业宣传片汇报片拍摄
  • 建设拼多多一样网站需要多少钱免费的网页游戏
  • asp.net网站连接mysql郴州做网站公司
  • 河南网站排名优化佛山网站设计讯息
  • 江苏省建设工程协会网站要搭建网站
  • 邯郸信息港二手车出售seo是东莞企业网站排seo
  • 建一个类似淘宝的网站需要多少钱园区 网站建设方案
  • 第一ppt模板免费下载网站郑州百度推广网站建设
  • 门户网站那个程序比较网站设计制作简单实例
  • html5做网站北京最大做网站的公司有哪些
  • 网站开发的例子自媒体怎么入门
  • 新乡做网站公兰州网络推广制度
  • 中国设计网站官网地址wordpress 迁移插件
  • 二手交易网站建设内容策划推广平台大全
  • 网络传媒网站网站策划方案 优帮云
  • 如何建设淘宝客网站手机网站制作
  • 整站优化该怎么做证件查询官网入口
  • 哪里有网站app制作wordpress post date
  • 富阳网站设计网站建设佰金手指科杰六