当前位置:网站首页>515. Find Largest Value in Each Tree Row
515. Find Largest Value in Each Tree Row
2022-06-25 12:51:00 【SUNNY_ CHANGQI】

The first time to pass in once try, congratulate me
/** * 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:
vector<int> largestValues(TreeNode* root) {
if (!root) {
return {
};
}
queue<TreeNode *> q;
vector<int> res;
q.push(root);
while(!q.empty()){
int len = q.size();
int max_val = INT_MIN;
while (len){
TreeNode *tmp = q.front();
max_val = max(tmp->val, max_val);
q.pop();
--len;
if (tmp->left) {
q.push(tmp->left);
}
if (tmp->right) {
q.push(tmp->right);
}
}
res.emplace_back(max_val);
}
return res;
}
};
边栏推荐
- PPT绘图之AI助力论文图
- Laravel is not logged in and cannot access the background by entering the URL
- CUDA error: unspecified launch failure
- Go novice exploration road 2
- Swagger document generated by node project API in vscode
- Parse JSON format data and save it to entity class
- 出手即不凡,这很 Oracle!
- My first experience of go+ language -- a collection of notes on learning go+ design architecture
- 更新pip&下载jupyter lab
- QT TCP UDP network communication < theory >
猜你喜欢

High performance + million level Excel data import and export

Baidu search stability analysis story

(7) Pyqt5 tutorial -- > > window properties and basic controls (continuous update)

美创入选“2022 CCIA中国网络安全竞争力50强”榜单

初识CANOpen

架构师需要具备的能力

Geospatial search - > R tree index

2021-09-02

Swagger document generated by node project API in vscode
![按权重随机选择[前缀和+二分+随机target]](/img/84/7f930f55f8006a4bf6e23ef05676ac.png)
按权重随机选择[前缀和+二分+随机target]
随机推荐
Penetration tool environment -- use of cknife Chinese kitchen knife
Render values to corresponding text
2021-10-21
Common software numerical filtering methods (I) have been applied
Connect with the flight book and obtain the user information according to the userid
2021-09-30
2021-09-28
按权重随机选择[前缀和+二分+随机target]
Visual studio2019 link opencv
Swagger document generated by node project API in vscode
Figure explanation of fiborache sequence
The difference between this and super and their respective functions
2021-09-22
地理空间搜索 ->R树索引
微信全文搜索技术优化
架构师必备的七种能力
Baidu search stability analysis story
Optimal solution for cold start
Laravel echart statistical chart line chart
重装cuda/cudnn/pytorch