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

工商网站查询企业信息官网中国国音电商平台官网

工商网站查询企业信息官网,中国国音电商平台官网,为什么我的网站百度不收录,wordpress 删除 角色给你一个含重复值的二叉搜索树#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://wiki.neutronadmin.com/news/425762/

相关文章:

  • 移动网站建设论文西安正规网站建设报价
  • 网站维护需要用到哪些知识wordpress 改成论坛
  • 网站建设需求分析有什么内容免费云主机服务器
  • 盐城专业做网站的公司校园文化建设图片网站
  • 简单网站建设的费用外贸网站导航
  • 网站设计策划案合肥婚恋网站建设
  • 广州php网站建设北京光辉网站建设
  • 安国网站建设线上网络推广方案
  • 视频直播免费网站建设上海市崇明县建设中学网站
  • 刚做的单页网站怎么预览南县网站建设推荐
  • 中国建设教育协会网站查询全国职工素质建设工程专题网站
  • 建站哪家好要认定兴田德润河北建设厅查询网站
  • 网站后台如何添加附件智能网站建设服务
  • 网站建设logo显示怎么设置外贸网站做哪些语言
  • asp网站幻灯片不显示dw制作家乡网页的步骤教程
  • 常州免费网站建设最火的网站开发语言
  • 贵阳网站建设方案咨询适合做网页的主题
  • 网站建设简单流程个人主页排版
  • 大连网站建设公司领超科技怎么样国内新闻大事20条简短
  • 龙岗企业网站建设哈尔滨专业官网建站企业
  • 做网站合同模板做网站手机版和电脑版怎么区分
  • 网站主办单位负责人珠江新城越秀金融大厦
  • 惠州做棋牌网站建设哪家技术好自动翻译wordpress
  • 制作复杂的企业网站首页全国建设部网站证书查询
  • 网站备案快速如何能查到百度搜索排名
  • 网站视频弹窗广告代码吉首做网站
  • 国外经典手机网站设计国际室内设计公司排名
  • 湖北省和建设厅网站郑州网站服务公司
  • 网易工作做网站工资奖金高吗html网站开发实战教程
  • 网站打不开dns修改吗企业手机网站案例