当前位置:网站首页>199. Right view of binary tree - breadth search
199. Right view of binary tree - breadth search
2022-07-03 18:19:00 【The_ Dan】
class Solution {
public:
vector<int> rightSideView(TreeNode* root) {
vector<int> vecInt;
if(!root)
return vecInt;
deque<TreeNode*> que;
que.push_back(root);
while(!que.empty()){
int n = que.size();
vecInt.push_back(que.back() -> val); // Add the last element , That is, the rightmost element
for(auto i = 0; i < n; i++){
// Level traversal
if(que.front() -> left)
que.push_back(que.front() -> left);
if(que.front() -> right)
que.push_back(que.front() -> right);
que.pop_front();
}
}
return vecInt;
}
};
Accepted
215/215 cases passed (4 ms)
Your runtime beats 65.19 % of cpp submissions
Your memory usage beats 90.76 % of cpp submissions (11.6 MB)
边栏推荐
- Applet with multiple tabs and Swipers + paging of each tab
- PHP MySQL inserts multiple pieces of data
- Design limitations of structure type (struct)
- Mature port AI ceaspectus leads the world in the application of AI in terminals, CIMC Feitong advanced products go global, smart terminals, intelligent ports, intelligent terminals
- BFS - topology sort
- Enterprise custom form engine solution (12) -- form rule engine 2
- Golang string (string) and byte array ([]byte) are converted to each other
- Theoretical description of linear equations and summary of methods for solving linear equations by eigen
- win32:堆破坏的dump文件分析
- [linux]centos 7 reports an error when installing MySQL "no package MySQL server available" no package ZABBIX server MySQL available
猜你喜欢
2022-2028 global lithium battery copper foil industry research and trend analysis report
模块九作业
How to track the real-time trend of Bank of London
Summary and Reflection on the third week of winter vacation
2022-2028 global petroleum pipe joint industry research and trend analysis report
AcWing 271. Teacher Yang's photographic arrangement [multidimensional DP]
Talk about the design and implementation logic of payment process
Class exercises
PHP MySQL inserts data
网格图中递增路径的数目[dfs逆向路径+记忆dfs]
随机推荐
Computer graduation project PHP library book borrowing management system
This diversion
PHP MySQL inserts data
2022-2028 global lithium battery copper foil industry research and trend analysis report
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
微服务组件Sentinel控制台调用
Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028
网格图中递增路径的数目[dfs逆向路径+记忆dfs]
[combinatorics] generating function (example of using generating function to solve the number of solutions of indefinite equation)
A. Berland Poker &1000【简单数学思维】
Bloom filter [proposed by bloom in 1970; redis cache penetration solution]
Talk about the design and implementation logic of payment process
Change the single node of Postgres database into master-slave
Micro service component sentinel console call
On Data Mining
A. Odd Selection【BruteForce】
Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
How to expand the capacity of golang slice slice
一入“远程”终不悔,几人欢喜几人愁。| 社区征文