当前位置:网站首页>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)
边栏推荐
- PHP MySQL inserts data
- Gear2021 monthly update - December
- [combinatorics] generating function (positive integer splitting | unordered | ordered | allowed repetition | not allowed repetition | unordered not repeated splitting | unordered repeated splitting)
- Kotlin的協程:上下文
- 企业级自定义表单引擎解决方案(十二)--表单规则引擎2
- (8) HS corner detection
- PHP MySQL inserts multiple pieces of data
- How do microservices aggregate API documents? This wave of operation is too good
- Win32: analyse du fichier dump pour la défaillance du tas
- Fedora 21 安装 LAMP 主机服务器
猜你喜欢
微服务组件Sentinel控制台调用
win32:堆破坏的dump文件分析
Redis cache avalanche, penetration, breakdown
聊聊支付流程的设计与实现逻辑
2022-2028 global aircraft head up display (HUD) industry research and trend analysis report
Codeforces Round #803 (Div. 2) C. 3SUM Closure
As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
Computer graduation design PHP campus address book telephone number inquiry system
Redis on local access server
(9) Opencv Canny edge detection
随机推荐
Valentine's day, send you a little red flower~
2022-2028 global scar care product industry research and trend analysis report
win32:堆破坏的dump文件分析
How to expand the capacity of golang slice slice
Bloom filter [proposed by bloom in 1970; redis cache penetration solution]
PHP MySQL reads data
How to install PHP on Ubuntu 20.04
SDNUOJ1015
Class exercises
Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
webcodecs
SQL injection -day16
Computer graduation design PHP campus address book telephone number inquiry system
Bidding procurement scheme management of Oracle project management system
2022-2028 global plasmid DNA cdmo industry research and trend analysis report
English grammar_ Adjective / adverb Level 3 - multiple expression
Sensor 调试流程
Computer graduation design PHP sports goods online sales system website
Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028
(9) Opencv Canny edge detection