当前位置:网站首页>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)
边栏推荐
- Fedora 21 installs lamp host server
- 2022-2028 global scar care product industry research and trend analysis report
- English语法_名词 - 分类
- English grammar_ Adjective / adverb Level 3 - multiple expression
- Codeforces Round #803 (Div. 2) C. 3SUM Closure
- Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
- PHP MySQL reads data
- English grammar_ Noun classification
- PHP MySQL inserts multiple pieces of data
- Naoqi robot summary 27
猜你喜欢
Golang string (string) and byte array ([]byte) are converted to each other
Redis core technology and practice - learning notes (11): why not just string
Win 11 major updates, new features love love.
Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
Class exercises
Win32: analyse du fichier dump pour la défaillance du tas
Discussion sur la logique de conception et de mise en oeuvre du processus de paiement
On Data Mining
List的stream中Long对象与long判等问题记录
Valentine's day, send you a little red flower~
随机推荐
On Data Mining
[教程]在 CoreOS 上构建你的第一个应用
Solve the problem of inaccurate network traffic monitored by ZABBIX with SNMP
Research on Swift
English语法_形容词/副词3级 - 倍数表达
PHP MySQL inserts data
[combinatorics] generating function (summation property)
How to analyze the rising and falling rules of London gold trend chart
[tutorial] build your first application on coreos
Redis core technology and practice - learning notes (VI) how to achieve data consistency between master and slave Libraries
2022-2028 global sepsis treatment drug industry research and trend analysis report
[combinatorics] generating function (positive integer splitting | unordered | ordered | allowed repetition | not allowed repetition | unordered not repeated splitting | unordered repeated splitting)
小程序 多tab 多swiper + 每个tab分页
A. Berland Poker & 1000 [simple mathematical thinking]
一入“远程”终不悔,几人欢喜几人愁。| 社区征文
Codeforces Round #803 (Div. 2) C. 3SUM Closure
PHP MySQL preprocessing statement
Keepalived setting does not preempt resources
Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
English grammar_ Adjective / adverb Level 3 - multiple expression