当前位置:网站首页>Mode in BST (binary tree & Notes on question brushing)
Mode in BST (binary tree & Notes on question brushing)
2022-07-05 04:32:00 【Toolman firefly】
Violence statistics . Common tree practice , Roll it first , Let's look at the specific frequency
- map: The internal is RB Trees , The output is orderly .
- unordered_map yes hash function , Output disorder
private:
unordered_map<int,int> mp;
public:
void dfs(TreeNode* cur_node)
{
if(cur_node==nullptr) return ;
mp[cur_node->val]++;
dfs(cur_node->left);
dfs(cur_node->right);
}
bool static cmp(const pair<int,int>&a,const pair<int,int>&b)
{
return a.second>b.second;
}
vector<int> FindNode(TreeNode* root)
{
vector<int> res;
if(root==nullptr) return ;
dfs(root);
vector<pair<int,int>> vec(mp.begin(),mp.end());/* Very important */
sort(vec.begin(),vec.end(),cmp);/* Note the return value of the function */
res.push_back(vec[0].first);
for(int i=1;i<vec.size();i++)
{
if(vec[i].second==vec[0].second)
res.push_back(vec[i].first);
else
break;
}
return res;
}
Because of the mention of BST We're going to use BST Characteristics of ,BST Middle order traversal of , Is an ascending array ‘
private:
int count;
int max_count;
TreeNode* pre_node;
vector<int> res;
public:
void dfs(TreeNode* cur_node);
{
if(cur_node==nullptr) return;
dfs(cur_node->left);/*================================ Left */
if(pre_node==nullptr) count=1;/* First node */
else if(pre_node->val==cur_node->val) count++;/* The same value as the previous node */
else count=1;/* Different from the previous node value */
pre_node=cur_node;/* Update is a node */
if(count==max_count) res.push_back(cur->val);
if(count>max_count) {
max_count=count;
res.clear();
res.push_baxk(cur_node->val);
}
dfs(cur_node->right);/*============================== Right */
}
vector<int> FindNode(TreeNode* root)
{
count=0;
max_count=0;
pre_node=nullptr;
res={
};
dfs(root);
return res;
}
边栏推荐
- 【UNIAPP】系统热更新实现思路
- 美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败
- How to force activerecord to reload a class- How do I force ActiveRecord to reload a class?
- Ctfshow web entry code audit
- Neural networks and deep learning Chapter 2: machine learning overview reading questions
- Aperçu en direct | Services de conteneurs ACK flexible Prediction Best Practices
- windows下Redis-cluster集群搭建
- 2022-2028 global and Chinese video coding and transcoding Market Research Report
- Here comes the Lantern Festival red envelope!
- 这是一个不确定的时代
猜你喜欢

Raki's notes on reading paper: soft gazetteers for low resource named entity recognition

Wenet: E2E speech recognition tool for industrial implementation

解密函数计算异步任务能力之「任务的状态及生命周期管理」

直播預告 | 容器服務 ACK 彈性預測最佳實踐

How to get the first few pieces of data of each group gracefully

Setting up redis cluster cluster under Windows

Key review route of probability theory and mathematical statistics examination

Kwai, Tiktok, video number, battle content payment
![[phantom engine UE] package error appears! Solutions to findpin errors](/img/d5/6747e20da6a8a4ca461094bd27bbf0.png)
[phantom engine UE] package error appears! Solutions to findpin errors

Seven join join queries of MySQL
随机推荐
蛇形矩阵
2022-2028 global and Chinese FPGA prototype system Market Research Report
Sequelize. JS and hasmany - belongsto vs hasmany in serialize js
直播预告 | 容器服务 ACK 弹性预测最佳实践
QT Bluetooth: a class for searching Bluetooth devices -- qbluetooth devicediscoveryagent
[phantom engine UE] the difference between running and starting, and the analysis of common problems
假设检验——《概率论与数理统计》第八章学习笔记
Neural network and deep learning Chapter 1: introduction reading questions
【UNIAPP】系统热更新实现思路
Network security - record web vulnerability fixes
Ctfshow web entry code audit
Label exchange experiment
A solution to the problem that variables cannot change dynamically when debugging in keil5
指针函数(基础)
【FineBI】使用FineBI制作自定义地图过程
Hypothesis testing -- learning notes of Chapter 8 of probability theory and mathematical statistics
直播預告 | 容器服務 ACK 彈性預測最佳實踐
Introduction to RT thread kernel (4) -- clock management
[Chongqing Guangdong education] 2408t Chinese contemporary literature reference test in autumn 2018 of the National Open University
Learning MVVM notes (1)