In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces you the example analysis of the python binary tree problem, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Topic link
LeetCode 199. The right view of the binary tree [1]
Topic description
Given a binary tree, imagine yourself standing on the right side of it, returning the node values you can see from the right in the order from top to bottom.
Example 1
Input: [1 val 2, right 3, res.push_back (x); for (int I = right.size (), sz = left.size (); I
< sz; ++i) { res.push_back(left[i]); } return res; }};bfs(c++)class Solution {public: vector rightSideView(TreeNode* root) { vector res; queue Q; if (root) Q.push(root); while (!Q.empty()) { int sz = Q.size(); while (sz--) { TreeNode* node = Q.front(); Q.pop(); if (!sz) res.push_back(node->Val); if (node- > left) Q.push (node- > left); if (node- > right) Q.push (node- > right);}} return res;}}. This is the end of the example analysis on python binary tree. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.