当前位置:网站首页>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)
边栏推荐
- Bloom filter [proposed by bloom in 1970; redis cache penetration solution]
- 网格图中递增路径的数目[dfs逆向路径+记忆dfs]
- List的stream中Long对象与long判等问题记录
- [Yu Yue education] family education SPOC class 2 reference materials of Shanghai Normal University
- G1 garbage collector of garbage collector
- STM32 realizes 74HC595 control
- MySQL has been stopped in the configuration interface during installation
- Ml (machine learning) softmax function to realize the classification of simple movie categories
- Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
- PHP MySQL where clause
猜你喜欢
![Bloom filter [proposed by bloom in 1970; redis cache penetration solution]](/img/f9/27a75454b464d59b9b3465d25fe070.jpg)
Bloom filter [proposed by bloom in 1970; redis cache penetration solution]

(9) Opencv Canny edge detection

Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028

Computer graduation design PHP makeup sales Beauty shopping mall

Redis core technology and practice - learning notes (IX): slicing cluster

Grammaire anglaise Nom - Classification

Redis cache avalanche, penetration, breakdown

PHP MySQL inserts data

Naoqi robot summary 27

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
随机推荐
Theoretical description of linear equations and summary of methods for solving linear equations by eigen
Naoqi robot summary 27
Summary and Reflection on the third week of winter vacation
[combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation)
2022-2028 global sepsis treatment drug industry research and trend analysis report
WebView module manages the application window interface to realize the logical control and management operation of multiple windows (Part 1)
[enumeration] annoying frogs always step on my rice fields: (who is the most hateful? (POJ hundred practice 2812)
[combinatorics] generating function (positive integer splitting | unordered | ordered | allowed repetition | not allowed repetition | unordered not repeated splitting | unordered repeated splitting)
Computer graduation project PHP library book borrowing management system
Setinterval CPU intensive- Is setInterval CPU intensive?
Module 9 operation
(8) HS corner detection
Records of long objects and long judgments in the stream of list
A. Odd Selection【BruteForce】
Sensor 调试流程
Nodejs (01) - introductory tutorial
How to deploy applications on kubernetes cluster
English语法_名词 - 分类
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
PHP MySQL preprocessing statement