Example Analysis of python binary Tree problem
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.