当前位置:网站首页>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)
边栏推荐
- OpenSSL的SSL/BIO_get_fd
- Talk about the design and implementation logic of payment process
- MySQL grouping query
- Win 11 major updates, new features love love.
- Introduction to PHP MySQL
- 微服务组件Sentinel控制台调用
- English语法_名词 - 分类
- 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
- BFS - topology sort
- Computer graduation design PHP makeup sales Beauty shopping mall
猜你喜欢

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

Module 9 operation

2022-2028 global lithium battery copper foil industry research and trend analysis report

Talk about the design and implementation logic of payment process

Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028

模块九作业

PHP MySQL inserts data

Records of long objects and long judgments in the stream of list

Should I be laid off at the age of 40? IBM is suspected of age discrimination, calling its old employees "dinosaurs" and planning to dismiss, but the employees can't refute it

Five problems of database operation in commodity supermarket system
随机推荐
Line by line explanation of yolox source code of anchor free series network (6) -- mixup data enhancement
Ml (machine learning) softmax function to realize the classification of simple movie categories
Line by line explanation of yolox source code of anchor free series network (5) -- mosaic data enhancement and mathematical understanding
[combinatorics] generating function (linear property | product property)
The number of incremental paths in the grid graph [dfs reverse path + memory dfs]
[combinatorics] generating function (summation property)
Fedora 21 安装 LAMP 主机服务器
Naoqi robot summary 27
Module 9 operation
[combinatorics] generating function (positive integer splitting | unordered | ordered | allowed repetition | not allowed repetition | unordered not repeated splitting | unordered repeated splitting)
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
How to expand the capacity of golang slice slice
Market demand survey and marketing strategy analysis report of global and Chinese pet milk substitutes 2022-2028
Computer graduation design PHP makeup sales Beauty shopping mall
Image 24 bits de profondeur à 8 bits de profondeur
Micro service component sentinel console call
(9) Opencv Canny edge detection
[combinatorics] generating function (property summary | important generating function)*
win32:堆破壞的dump文件分析
SDNUOJ1015