当前位置:网站首页>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)
边栏推荐
- 基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
- STM32 realizes 74HC595 control
- 企业级自定义表单引擎解决方案(十二)--表单规则引擎2
- Count the number of pixel values in the image
- (9) Opencv Canny edge detection
- Remote office tools sharing | community essay solicitation
- Line by line explanation of yolox source code of anchor free series network (6) -- mixup data enhancement
- [combinatorics] generating function (linear property | product property)
- Summary and Reflection on the third week of winter vacation
- Solve the problem of inaccurate network traffic monitored by ZABBIX with SNMP
猜你喜欢

Win32: analyse du fichier dump pour la défaillance du tas
![The number of incremental paths in the grid graph [dfs reverse path + memory dfs]](/img/57/ff494db248171253996dd6c9110715.png)
The number of incremental paths in the grid graph [dfs reverse path + memory dfs]

Prototype inheritance..

Have you learned the correct expression posture of programmers on Valentine's day?

Computer graduation design PHP campus address book telephone number inquiry system

Micro service component sentinel console call

An academic paper sharing and approval system based on PHP for computer graduation design

win32:堆破坏的dump文件分析

模块九作业

Redis cache avalanche, penetration, breakdown
随机推荐
English語法_名詞 - 分類
How to track the real-time trend of Bank of London
Keepalived 设置不抢占资源
PHP MySQL where clause
win32:堆破坏的dump文件分析
Five problems of database operation in commodity supermarket system
Market demand survey and marketing strategy analysis report of global and Chinese pet milk substitutes 2022-2028
毕业总结
Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
SDNUOJ1015
PHP MySQL create database
English grammar_ Noun classification
Redis core technology and practice - learning notes (IX): slicing cluster
MySQL has been stopped in the configuration interface during installation
(9) Opencv Canny edge detection
[combinatorics] exponential generating function (concept of exponential generating function | permutation number exponential generating function = combinatorial number ordinary generating function | e
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
Redis cache avalanche, penetration, breakdown
OpenSSL的SSL/BIO_get_fd
Win32: dump file analysis of heap corruption