当前位置:网站首页>515. Find Largest Value in Each Tree Row
515. Find Largest Value in Each Tree Row
2022-06-25 12:10: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;
}
};
边栏推荐
- 聊聊高可用的 11 个关键技巧
- Possible causes of wechat applet decryption failure
- PHP parsing QR code content
- Ramda rejects objects with null and empty object values in the data
- Array reorder based on a field
- Ubuntu uninstalling PHP
- Lighten the source code -- lighten the app system development function introduction to the beautiful world lighten the app system development source code in China
- ECSHOP commodity page multi-attribute batch purchase plug-ins ECSHOP wholesale plug-ins multi-attribute order placing, multi-attribute batch purchase of commodities
- PHP appends the same elements to a two-dimensional array
- (3) Pyqt5 tutorial -- > signal and slot preliminary test
猜你喜欢

ECSHOP commodity page multi-attribute batch purchase plug-ins ECSHOP wholesale plug-ins multi-attribute order placing, multi-attribute batch purchase of commodities

2021-09-22

The drop-down box renders numbers instead of the corresponding text. How to deal with it

Go from 0 to 1. Obtain the installation package, get, post request, params, body and other parameters

线上服务应急攻关方法论

高性能负载均衡架构如何实现?

ECSHOP commodity wholesale multi attribute multi specification multi inventory batch purchase ECSHOP wholesale plug-in ECSHOP multi attribute order

Matlab simulation of m-sequence
![最大数[抽象排序之抽象规则]](/img/47/f6bafacc95f487854a3e304325f3f0.png)
最大数[抽象排序之抽象规则]

ECSHOP video list_ ECSHOP uploading video, video classification, video list playing video function
随机推荐
Flutter automatically disappears after receiving push
为何数据库也云原生了?
C program linking SQLSERVER database: instance failed
When MySQL queries fields in JSON format, it takes a property value of JSON data
PHP multidimensional array sorting
Development with courtesy -- share the source code of the secondary development of the app system of the imitation shopping mall
MySQL and excel tables importing database data (Excel for MySQL)
Wait for the end of the network request in the uniapp Onshow method before executing the subsequent code content
STM32 stores float data in flash
(4) Pyqt5 tutorial -- > Custom signal and slot (super winding...)
Embedded software development written examination and interview notes (latest update: February 17, 2022)
The drop-down box renders numbers instead of the corresponding text. How to deal with it
JS SMS countdown implementation (simple code)
(2) Pyqt5 tutorial -- > using qtdesigner to separate interface code
Online blind box system development function introduction and some source code sharing
Laravel echart statistical chart line chart
ECSHOP commodity page multi-attribute batch purchase plug-ins ECSHOP wholesale plug-ins multi-attribute order placing, multi-attribute batch purchase of commodities
Concise H5 error page
Methods of strings in JS charat(), charcodeat(), fromcharcode(), concat(), indexof(), split(), slice(), substring()
Laravel excel export