当前位置:网站首页>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)
边栏推荐
- [combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation)
- Change the single node of Postgres database into master-slave
- Codeforces Round #803 (Div. 2) C. 3SUM Closure
- English語法_名詞 - 分類
- Redis core technology and practice - learning notes (11): why not just string
- Naoqi robot summary 27
- [enumeration] annoying frogs always step on my rice fields: (who is the most hateful? (POJ hundred practice 2812)
- AcWing 271. Teacher Yang's photographic arrangement [multidimensional DP]
- Remote office tools sharing | community essay solicitation
- 统计图像中各像素值的数量
猜你喜欢

How to draw non overlapping bubble chart in MATLAB

win32:堆破坏的dump文件分析

Nodejs (01) - introductory tutorial

PHP MySQL inserts multiple pieces of data

(8) HS corner detection

Summary and Reflection on the third week of winter vacation

Investigation on the operation prospect of the global and Chinese Anti enkephalinase market and analysis report on the investment strategy of the 14th five year plan 2022-2028

2022-2028 global petroleum pipe joint industry research and trend analysis report

Computer graduation project PHP library book borrowing management system

On Data Mining
随机推荐
[Tongxin UOS] scanner device management driver installation
Remote office tools sharing | community essay solicitation
supervisor监控Gearman任务
[combinatorics] generating function (example of generating function | calculating generating function with given general term formula | calculating general term formula with given generating function)
How to draw non overlapping bubble chart in MATLAB
【统信UOS】扫描仪设备管理驱动安装
OpenSSL的SSL/BIO_get_fd
小程序 多tab 多swiper + 每个tab分页
The number of incremental paths in the grid graph [dfs reverse path + memory dfs]
An academic paper sharing and approval system based on PHP for computer graduation design
Five problems of database operation in commodity supermarket system
Life perception 1
Image 24 bit depth to 8 bit depth
BFS - topology sort
[untitled]
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
[combinatorics] exponential generating function (concept of exponential generating function | permutation number exponential generating function = combinatorial number ordinary generating function | e
Summary and Reflection on the third week of winter vacation
Line by line explanation of yolox source code of anchor free series network (6) -- mixup data enhancement
Ssl/bio of OpenSSL_ get_ fd